2011-01-29 81 views
5
$ py manage.py migrate turkey 
Running migrations for turkey: 
- Migrating forwards to 0001_initial. 
> turkey: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 `turkey_demorecs` 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. 

出于某种原因,当我尝试它时,我得到了这个。 但我的其他设置在MyISAM中。Django的南方(迁移工具)是否适用于innodb?

Innodb为什么不起作用?

回答

1

是的,South确实支持InnoDB。您可以删除“迁移”文件夹的内容,并重新运行schemamigration,迁移并在此发布0001_initial文件的结果和内容? PS:确保先备份您的迁移文件夹或在源代码管理中。

rm -fr app/migrations/* 
./manage.py schemamigration app --initial 
./manage.py migrate app 
3

又见https://code.djangoproject.com/wiki/AlterModelOnSyncDB

与MySQL的安装程序,其默认的表存储引擎是MyISAM和我想使用InnoDB(使用中发现的食谱工作时,我曾同一种错误的发生在我身上上面的链接,我们使用post_syncdb信号来触发转换代码)。但是,当使用South创建新表时,他们首先使用MyISAM引擎创建,然后再进行转换。我错误地认为InnoDB表没有按照他们应该做的那样做,当时这些表实际上是MyISAM;因为该表是由信号转换,任何迁移错误将无法取消应用 - :

# add at the beginning of your migration 
if db.backend_name == 'mysql': 
    db.execute('SET storage_engine=INNODB') 

/

如果需要使用或创建InnoDB表,其中默认是MyISAM的,这跟来解决或者,如果你不介意的性能损失:

# add this to settings.py 
DATABASE_OPTIONS = { 
    "init_command": "SET storage_engine=INNODB", # XXX: performance hit... 
} 
+0

你确定吗?我们甚至没有原始错误。 – Tobu 2011-08-25 22:34:57

4

的InnoDB有外键,确保在做迁移的时候你是不是打破了数据库模型的约束。 (见http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html

MyISAM不具有约束的原生支持(虽然它似乎如果你选择做做http://dev.mysql.com/tech-resources/articles/mysql-enforcing-foreign-keys.html可以实现这一点)

因为MyISAM数据没有查收FK的关系,你没有得到的错误。然而InnoDB正在做一个检查,看起来你的迁移有问题。

1

你可以尝试添加到您的第一个迁移:

if db.backend_name == 'mysql': 
    db.execute('SET foreign_key_checks=0') 

这将禁用外键检查约束。

因为它是一个会话变量,所以您不必将其重置为1。

顺便说一句,如果你在beggining在迁移方法的结尾设置为0,返回1这是行不通的,因为南部生成SQL和他们在一起,但是当他们返回执行它。