Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django MySQL创建表时出错_Python_Mysql_Django - Fatal编程技术网

Python Django MySQL创建表时出错

Python Django MySQL创建表时出错,python,mysql,django,Python,Mysql,Django,我在Django论坛上提出了一个类似的问题。我如何解决这个问题 我还扩展了一个用户模型,如下所示:- 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

我在Django论坛上提出了一个类似的问题。我如何解决这个问题

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

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)
但我认为问题不在于模型,因为即使我从
已安装的应用程序列表中删除包含模型的应用程序,并运行
manage.py migrate
命令,它仍然会抛出相同的错误,即

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

不包括任何应用程序,它工作正常。任何线索都会非常有用。

检查数据库表的存储引擎。如前所述,旧的MySQL使用MyISAM,这与实际的InnoDB存储引擎不兼容。因此,如果您的数据库对不同的表具有不同的存储引擎,并且您尝试生成外键,则可能会发现此错误。至少,这是我的情况:)
希望这有助于您使用python manage.py syncdb命令吗?该命令已被弃用,因此未使用。我直接应用了
python manage.py migrate
。我尝试了
python manage.py makemgration appname
,然后
python manage.py migrate
,它成功了。但我必须为每个应用程序执行
python manage.py makemgration appname
。如何一次迁移所有应用??这是第一次。我遵循这些步骤。第一步:-
python manage.py makemigrations
。它显示
未检测到任何更改
。然后第二步
python manage.py迁移
。它创建了所有的表,并在抛出我在问题中指出的相同错误之间停顿。对每个应用程序执行makemigration,然后运行
migrate
对我来说很有用。但是,每个应用程序都需要这样做吗?如果我有20-30个应用呢<代码>在所有应用程序上进行迁移
并不是一个可行的解决方案。