Pesky "Table" my_table "already exists" in Django-South

In Django-South: I changed. I successfully completed the initial migration for myapp, but for some reason, after I made changes to my model and move on to

./manage.py schemamigration myapp --auto ./manage.py migrate myapp 

And I get a lot of tracing that ends with:

 (1050, "Table 'my_table' already exists") 

After much searching, I found and tried this:

 ./manage.py migrate myapp --fake 

And then I move on to migration, but to no avail; same error.

Any suggestions?

+6
django django-south
source share
3 answers

I just got the same error and found this question by searching.

My problem was that my second migration, which I created using the --initial flag, i.e.

 $ ./manage.py startapp foo $ ./manage.py schemamigration --initial foo $ ./manage.py migrate foo 

... make some changes to foo ...

 $ ./manage.py schemamigration --initial foo 

(oops!)

 $ ./manage.py migrate foo 

... and I get an error message, and the migration failed because in the second migration the South is trying to create an already created table.

Decision

In my migration folder:

 $ ls foo/migrations 0001_initial.py 0002_initial.py 

remove the second migration and re-export the second migration with the correct --auto flag:

 $ rm foo/migrations/0002_initial.py $ ./manage.py schemamigration --auto foo $ ./manage.py migrate foo 

Success!

There may be other reasons causing this error, but it was bad!

+7
source share

Is this an existing application?

In this case, you will need to convert it in addition to the fake bit.

There are good documents here when converting an existing application.

Although they are quite difficult to find if you do not know where they are already (;

To convert by adding south to installed applications:

 ./manage.py syncdb ./manage.py convert_to_south myapp ./manage.py migrate myapp 0001 --fake 
+4
source share

this problem actually occurs if one of the cases:

1) You did "schemamigration app_name --initial" after one of them "--auto" 2) You interrupted the last migration that you did.

To solve this problem, you apply the following:

1) mark the last migration of the circuit as false.

 python manage.py schemamigration app_name --fake 

Note. Make sure that the layout of the models is similar to the layout of tables in the database.

2) apply the migration again by doing

 python manage.py schemamigration app_Name --auto python manage.py migrate app-Name 

Note. Sometimes you can manually add a specific field that you have already added using the following syntax.

 python manage.py schemamigration app_name --add-field My_model.added_field 

More details. regarding the south, you can check its documentation here .

0
source share

All Articles