Django MySQL错误创建表 [英] Django MySQL error creating tables

查看:208
本文介绍了Django MySQL错误创建表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Django论坛上提到的这张机票有类似的问题。我如何解决这个问题?

I've a similar problem as this ticket raised on Django forum. How do I solve this issue??

我还有一个扩展的用户模型,如下所示: -

I also have a User model extended, as follow:-

class Profile(models.Model):
    street_address = models.CharField(max_length=80, blank=True, null=True)
    city = models.CharField(max_length=80, blank=True, null=True)
    state = models.CharField(max_length=80, blank=True, null=True)
    zip = models.CharField(max_length=30, blank=True, null=True)
    country = models.CharField(max_length=50, blank=True, null=True)
    phone = models.CharField(max_length=50, blank=True, null=True)
    birth = models.DateField(blank=True, null=True)
    photo = models.ImageField(upload_to='media')
    user = models.OneToOneField(User,primary_key=True)

但我不认为问题是与模型,因为即使我删除包含模型的应用程序 INSTALLED_APPS 列表,并运行 manage.py migrate 命令,它st病人会发生相同的错误,即

But I dont think the problem is with the model, because even if I remove the app containing the model from the INSTALLED_APPS list, and run the manage.py migrate command, it still throws the same errors, ie

django.db.utils.OperationalError: (1005, "Can't create table 'db.#sql-456_113' (errno: 150)")

不包括任何应用程序工作正常。任何负责人都将非常有帮助。

Without including any of the apps, it works fine. Any lead will be really helpful.

推荐答案

检查数据库表的存储引擎。根据 here ,旧的MySQL使用的MyISAM与实际的InnoDB存储引擎不兼容。因此,如果您的数据库对于不同的表具有不同的存储引擎,并且尝试创建一个外键,则可能会发现此错误。至少这是我的情况:)
希望这有助于某人

Check the storage engine of your db tables. As refered here old MySQL used MyISAM which is incompatible with actual InnoDB storage engine. so, if your db has different storage engines for different tables and you try to make a Foreign Key, you will probably find this error. At least, this was my case :) hope this helps someone

这篇关于Django MySQL错误创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆