I'm using Django 1.7, PostgresApp (PostgreSQL 9.4), Python 2.7.
I have followed this tutorial for setting up and creating the app: https://docs.djangoproject.com/en/1.9/intro/tutorial02/
In the Python shell, I kept getting errors like "ProgrammingError: relation "app_table" does not exist" for my database schema.
So I used the classes from the tutorial:
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
and then in the shell I got (the correct values):
>>> Question.objects.all()
[]
>>> Choice.objects.all()
[]
Then, modifying the name Choice to MyChoice gives this:
>>> Question.objects.all()
[]
>>> MyChoice.objects.all()
...
ProgrammingError: relation "app_mychoice" does not exist.
Why is this happening? I tried the answers suggested in other posts
./manage.py makemigrations;
./manage.py migrate auth;
./manage.py migrate and
python manage.py syncdb
but nothing worked.
Choice(models.Model)
toMyChoice(models.Model)
? – Hybrid Jan 7 '16 at 14:03syncdb
for Django 1.7+. Why are you trying to change the model name fromChoice
toMyChoice
? Did running./manage.py makemigrations
create a migration to rename the table? What are the contents of your app's migrations folder, and which ones have you run? You could try dropping and recreating the database, then deleting the migrations and running makemigrations again. – Alasdair Jan 7 '16 at 14:03makemigrations
created a migration with the names updated. I dropped and recreated the database and I get the same error. – daria Jan 7 '16 at 14:06fake
and use flags likeinitial
, but I don't want to give you a trial and error answer, hopefully someone who sees this has more experience with migrations and will be able to help – Hybrid Jan 7 '16 at 14:07