I have one model with the relevant fields setup. I ran manage.py migrate
then it created the a table in my database. I then ran manage.py makemigrations
so that it could create an initial migration file with prefix '0001'. I added another field to my model and then ran manage.py makemigrations
again, which created another migration file with prefix '0002'. When I run manage.py migrate
now it still looks at the first migration file and so throws out an error that the 'Table already exists'. How can I make it only look at the latest migration file so that it adds the new column to the table? I'm using MySQL.
This will never happen unless django detects (thinks) that the database has not been setup, and tries to initialise the tables with a schema.
Looks like your tables are already setup, but this is not known to django. That is why it tries to start applying the first migration - the table creation and schema is included in that.
You can use the --fake
and --fake-initial
options as per your specific problem, which tell django that the tables are already setup and ready, and to fake the migrations.
Useful links for more info:
django migrations - django documentation
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments