No Such Column Error in Django App After South Migration

Drew Cummins picture Drew Cummins · Nov 7, 2010 · Viewed 8k times · Source

I've run into the same issue presented by the commenter here: Django South - table already exists

There was no follow-up, so I thought I'd post a new question. I have a Django app whose migrations I manage with South. I added a field to my model then ran

./manage schemamigration my_app --auto

which ran as expected. Running

./manage migrate my_app

however, resulted in an error indicating that the table associated with the model I changed already exists. This led me to the above linked question, so running

./manage migrate my_app --fake

resolved the table error, but now I'm getting a Django error that the column associated with the new field does not exist.

./manage sqlall my_app

shows the schema to be as expected.

Any thoughts on how to remedy this are appreciated!

Answer

Ski picture Ski · Nov 7, 2010

Probably easiest way for you will be to start migrations from scratch.

Delete all migrations/* files for the app which you try to fix. Restore your models.py to the state which is at the moment on the database (by the help of version control tools, or just comment out the new fields). Then initialize migrations:

manage.py migrate my_app --delete-ghost-migrations
manage.py schemamigration my_app --init
manage.py migrate my_app --fake

This will create a record in migrations of what current database structure looks like.

Now add your changes to models.py and south will now what has changed:

manage.py schemamigration my_app --auto
manage.py migrate my_app