I have created a model and executed syncdb which had created the tables as my model was designed.
Afterwards I modified the model and executed makemigrations
which created the migrations ignoring the tables that syncdb had already created.
So I ended up with an error "relation already exists".
Why did makemigrations created everything from scratch? How do I fix this situation ?
makemigrations
creates new migrations based on the changes detected to your models.
Also, one thing to note is syncdb
command is deprecated since Django 1.7 and will be removed in Django 1.9. So, you should use the migrate
command.
From syncdb
docs:
Deprecated since version 1.7:
This command has been deprecated in favor of themigrate
command, which performs both the old behavior as well as executing migrations.
makemigration
always creates one migration file having all the changes. So, when you run makemigration
for first time it tries to find the previous migration file. if not found it creates one initial migration file. And when it tries to apply it to the db it finds the relation already exists. And thus throws error.
Best practice is, before updating model, create one migration then modify the model.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With