在现有数据库上安装South的问题。 MySql不支持'模式更改语句'

时间:2011-07-12 22:48:14

标签: mysql django django-south

我有一个带有现有数据库的django项目,我真的想避免转储或中断。我正在尝试安装South,但是当我运行初始迁移python manage.py migrate example时,我收到以下错误:

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")

所以显而易见的解决方案是运行给定的SQL,但我不知道它会做什么,如果它会丢弃表并丢失我的数据,就不想运行它。

我可以选择在不丢失数据的情况下让这次南迁移工作吗?

1 个答案:

答案 0 :(得分:8)

如果您的架构已经使用了用于创建0001_inital.py的models.py,那么您应该使用--fake运行初始迁移,以实质上告诉您已经处于架构的版本0001。