Django South - table already exists

Solution 1:

since you already have the tables created in the database, you just need to run the initial migration as fake

./manage.py migrate myapp --fake

make sure that the schema of models is same as schema of tables in database.

Solution 2:

Although the table "myapp_tablename" already exists error stop raising after I did ./manage.py migrate myapp --fake, the DatabaseError shows no such column: myapp_mymodel.added_field.

Got exactly the same problem!

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:

  1. Fake the first migration:

    ./manage migrate myapp 0001 --fake

  2. Roll with the rest of migrations:

    ./manage migrate myapp

Solution 3:

When I ran into this error, it had a different cause.

In my case South had somehow left in my DB a temporary empty table, which is used in _remake_table(). Probably I had aborted a migration in a way I shouldn't have. In any case, each subsequent new migration, when it called _remake_table(), was throwing the error sqlite3.pypysqlite2.dbapi2.OperationalError: table "_south_new_myapp_mymodel" already exists, because it did already exist and wasn't supposed to be there.

The _south_new bit looked odd to me, so I browsed my DB, saw the table _south_new_myapp_mymodel, scratched my head, looked at South's source, decided it was junk, dropped the table, and all was well.