Problem installing South on existing database. MyS

2019-05-09 11:27发布

问题:

I have a django project with an existing db that I would really like to avoid dumping or interrupting. I am attempting to install South but when I run my initial migration python manage.py migrate example I get the following error:

Running migrations for example:
- Migrating forwards to 0001_initial.
> example:0001_initial
! 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 `example_page` CASCADE; []
= DROP TABLE `example_likebydate` CASCADE; []
= DROP TABLE `example_followbydate` CASCADE; []

! The South developers regret this has happened, and would
! like to gently persuade you to consider a slightly
! easier-to-deal-with DBMS.
! NOTE: The error which caused the migration to fail is further up.
Traceback (most recent call last):

...

File "/usr/local/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.OperationalError: (1050, "Table 'example_page' already exists")

So the obvious solution is to run the the given SQL, but I don't know what that will do and don't want to run it if it's going to drop the table and lose my data.

What are my options for getting this South migration working without loosing the data?

回答1:

If your schema is already up to date with the models.py that was used to create 0001_inital.py then you should run your initial migration with --fake to essentially tell south that you are already at version 0001 of the schema.