我一直得到DatabaseError:(1825,“无法在表上添加外键约束......)

时间:2014-07-25 02:59:27

标签: mysql django django-south

我有一个现有的模型/表Foo

class Foo(models.Model):
    foo_id = models.CharField(max_length=64,
                              null=False,
                              primary_key=True,
                              unique=True)
    name = models.CharField(max_length=100,null=False)
    ...

    def __unicode__(self):
        return self.pk

    class Meta:
        app_label = 'foo'

现在,我想添加一个新模型/表FooBar

class FooBar(models.Model):
    foobar_id = models.AutoField(max_length=11,
                                 null=False,
                                 primary_key=True)
    foo = models.ForeignKey(Foo)
    bar = models.TextField()
    ...

    class Meta:
        app_lable = 'foo'

当我执行./manage.py schemamigration foo --auto./manage.py migrate foo时,出现错误:

Error in migration: schematicdb:0013_auto__add_foobar
DatabaseError: (1825, "Failed to add the foreign key constraint on table 'foo_foobar'.
Incorrect options in FOREIGN KEY constraint foo_db/foo_id_refs_foo_id_1e8ab51a'")

将MySQL与Django 1.5.4及South 0.8.2用于此。

我试过了ff。但无济于事:

DATABASES = {
    'default': {
        ...
        'OPTIONS': {
            'init_command': 'SET foreign_key_checks=0;',
        },
        'DEFAULT_STORAGE_ENGINE': 'InnoDB',
    }
}

所以现在,我不知道从哪里开始检查。

0 个答案:

没有答案