I want to migrate my app "landing" with south I write the following command
python manage.py migrate landing
but it shows the following error
Running migrations for landing:
- Migrating forwards to 0003_auto__chg_field_userinput_email2. landing:0001_initial
FATAL ERROR - The following SQL query failed: CREATE TABLE
landing_userinput
(id
integer AUTO_INCREMENT NOT NULL PRIMARY KEY,name
varchar(120) NOT NULL,city
varchar(120) NOT NULL,timestamp
datetim e NOT NULL)The error was: (1050, "Table 'landing_userinput' already exists") ! Error found during real run of migration! Aborting.
! Since you have a database that does not support running ! schema-altering statements in transactions, we have had ! to leave it in an interim state between migrations.
! You might be able to recover with: = DROP TABLE
landing_userinput
CASCAD E; []raise errorclass, errorvalue
django.db.utils.OperationalError: (1050, "Table 'landing_userinput' already exists")
Please give me suggestions to improve this bug.
Don't use syncdb
and migrate
at the same time; this will conflict as the initial migration will create a blank table.
If you have a new app and want to have it managed by south, your sequence of operations is:
./manage.py schemamigration landing --initial
-- this creates the initial migration, which creates the tables for the application. You only do this once../manage.py migrate landing
-- this will apply the migration. The first time you do this (with step #1 from above), this will create an empty table in the database.Once you have done the first two steps, whenever you make a change to your model, you run these two commands:
./manage.py schemamigration landing --auto
-- this will create the file that has the changes to your model (the migration).
./manage.py migrate landing
-- this will apply the new migration (this is the same command from above); and it will affect the changes to your database.
If you already have an existing application, install south and run syncdb
to create south's own database tables, then run ./manage.py convert_to_south yourappname
; this will do a "fake" migration and set it to the last state of the models. Then, follow the schemamigration yourappname --auto
and migrate
steps.
In your case, you have two options:
Drop the table (as the error suggests). This will get rid of all the data as well. If you are in development, this is the easiest way to get started fresh (you should also use fixtures if you want to provide some default data for your models).
You can use the --fake
option to trick south into thinking the operation has been done already. See the documentation for more.