Skip to content

Instantly share code, notes, and snippets.

@gladson
Created March 20, 2013 06:58
Show Gist options
  • Save gladson/5202824 to your computer and use it in GitHub Desktop.
Save gladson/5202824 to your computer and use it in GitHub Desktop.
South - django.db.utils.DatabaseError: table "myapp_tablename" already exists
I am trying to get started with South.
I had an existing database.
I added South (syncdb, schemamigration --initial).
I updated models.py to add a field.
I ran ./manage.py schemamigration myapp --auto
It seemed to find the field and said I could apply this with ./manage.py migrate myapp
Doing that gave the error:
django.db.utils.DatabaseError: table "myapp_tablename" already exists
tablename is the first table listed in models.py.
1.Firstly check the migration number which is causing this. Lets assume it is: 0010.
2.You need to:
./manage.py schemamigration myapp --add-field MyModel.added_field
./manage.py migrate myapp
if there is more than one field missing you have to repeat it for each field.
3.Now you land with a bunch of new migrations so remove their files from myapp/migrations (0011 and further if you needed to add multiple fields).
4.Run this:
./manage.py migrate myapp 0010
Now try ./manage.py migrate myapp
If it doesn't fail you're ready. Just doublecheck if any field's aren't missing.
EDIT:
This problem can also occur when you have a production database for which you install South and the first, initial migration created in other enviorment duplicates what you already have in your db. The solution is much easier here:
Fake the first migration:
./manage migrate myapp 0001 --fake
Roll with the rest of migrations:
./manage migrate myapp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment