自从mysql升级,以及使用mariaDB以来,很多不曾更新django中model的外键,

今天,按以前的思路写完外键之后,

migrate命令报错:

1005 - Can't create table `xxxDB`.`#sql-1_407` (errno: 150 "Foreign key constraint is incorrectly formed")

很郁闷,跟踪到mysql的日志:

SHOW ENGINE INNODB STATUS; 

------------------------
LATEST FOREIGN KEY ERROR
------------------------
2019-06-06 01:52:21 0x7f27202bf700 Error in foreign key constraint of table `xxxDB`.`cmdb_jiraworkflow`:
Alter table `xxxDB`.`cmdb_jiraworkflow` with foreign key constraint failed. Referenced table `xxxDB`.`cmdb_env` not found in the data dictionary near ' FOREIGN KEY (`env_name_id`) REFERENCES `cmdb_env` (`id`)'.

Referenced table not found in the data dictionary near ' FOREIGN KEY REFERENCES .

眼睛绿了,以写django写法有错,改了N次无果。

网上查了N多方案,没有对应我这个的。

最后,想起来了MYSQL升级的事端,以前的存储引擎都是MYISAM,更改为INNODB试试?

https://www.cnblogs.com/abeli/p/6533662.html

https://www.cnblogs.com/Baronboy/p/6037913.html

https://www.cnblogs.com/wanghuaijun/p/5829872.html

https://www.cnblogs.com/afish/p/3969756.html

结果,OK了~~~~

django的o数据库设置也更新如下:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'xxxDB',
        'USER': 'xx',
        'PASSWORD': 'xxx',
        'HOST': '10.xx.x.1',
        'PORT': '3306',
        'OPTIONS': {"init_command": "SET storage_engine=INNODB", }
    },
}

django migrate报错:1005 - Can't create table xxx (errno: 150 "Foreign key constraint is incorrectly formed")的更多相关文章

  1. MySQL创建外键约束的报错Error : Can't create table '#sql-534_185' (errno: 150)

    总得来说是因为两个表的字段类型不一致,例如: 两个字段的类型或大小不严格匹配,一个为tinyint,另一个为char:或一个为int(10)另一个为int(9)也是不行的,即使都为int(10),但一 ...

  2. MySQL添加外键报错 - referencing column 'xx' and referenced column 'xx' in foreign key constraint 'xx' are incompatible

    MySQL给两个表添加外键时,报错 翻译意思是:外键约束“xx”中的引用列“xx”和引用列“xx”不兼容 说明两个表关联的列数据类型不一致,比如:varchar 与 int,或者 int无符号 与 i ...

  3. Python Django migrate 报错解决办法

    1. 在现有基础上又添加一个表的时候migrate报错 migrate报错django.db.utils.OperationalError: (1050, "Table 'cmdb_eidc ...

  4. django migrate报错(提前删除表等)

    python3 manage.py makemigrations python3 manage.py migrate ##报错 改为##更改migrates的状态 python3 manage.py ...

  5. MySQL Error Number 1005 Can’t create table(Errno:150)

    mysql数据库1005错误解决方法 MySQL Error Number 1005 Can’t create table ‘.\mydb\#sql-328_45.frm’ (errno: 150) ...

  6. antd desgin vue 报错 Warning: Each record in table should have a unique `key` prop,or set `rowKey` to an unique primary key.

    警告:表的数据源中的每条记录都应该有一个唯一的“key”道具,或者将表的“rowKey”设置为一个唯一的主键, 只需要添加 :rowKey="record => record.id&q ...

  7. Django:报错 raise MigrationSchemaMissing("Unable to create the django_migrations table (%s)" % exc)

    Django 执行迁移生成表: python manage.py migrate 报错: raise MigrationSchemaMissing("Unable to create the ...

  8. Django(21)migrate报错的解决方案

    前言 在讲解如何解决migrate报错原因前,我们先要了解migrate做了什么事情,migrate:将新生成的迁移脚本.映射到数据库中.创建新的表或者修改表的结构. 问题1:migrate怎么判断哪 ...

  9. django报错解决:Invalid HTTP_HOST header: 'xxx.com'. You may need to add u'xxx.com' to ALLOWED_HOSTS.

    django版本:1.11.15 使用uwsgi+nginx运行django程序,出现报错,报错为:Invalid HTTP_HOST header: 'xxx.com:82'. You may ne ...

随机推荐

  1. Mac AXURE9 汉化

    1.下载汉化文件 https://pan.baidu.com/s/1qE0ZSvf210WLMfvi8RlMpg 2.把lang文件放在Resources文件夹下 3.重新打开Axure就ok了

  2. GetComponentsInChildren<Transform>(true)

    GetComponentsInChildren<Transform>(true);//游戏对象下的子物体激活的没激活的都会被拿到,包括游戏对象本身GetComponentsInChildr ...

  3. PHP7之Trait详解

    转自: https://www.jianshu.com/p/fc053b2d7fd1 php从以前到现在一直都是单继承的语言,无法同时从两个基类中继承属性和方法,为了解决这个问题,php出了Trait ...

  4. javaSE总结(二)--java面向对象

    一.类和对象 (1)类 [修饰符] class 类名{ //修饰符1:private public protected 三个最多出现其一 //修饰符2:abstract final 两个最多出现其一 ...

  5. stvd使用中的一些问题

    1.stm8_interrupt_vector.c 会莫名其妙的自动出现,而且都是在项目目录下.进行如下操作 2.stvd编译时遇到no default placement for segment . ...

  6. 前端调试代码 chrom 和 火狐禁用缓存 Disabled cache

    前端调试的时候经常遇到缓存问题, chrome : f12  ---> 找到 Disabled caceh 勾上 火狐: f12 找到 禁用缓存

  7. (转)为什么ssh一关闭,程序就不再运行了?

    ref :https://www.cnblogs.com/lomper/p/7053694.html 问题描述 当SSH远程连接到服务器上,然后运行一个程序,eg: ./test.sh, 然后把终端开 ...

  8. 正在阅读的tex教程

    https://liam.page/2014/09/08/latex-introduction/ https://www.jianshu.com/p/1d99b3c883a6 http://www.c ...

  9. win10 bcdedit testsigning

    win10 bcdedit testsigning # 禁用系统完整性检查和禁用驱动签名以及进入测试签名驱动模式> bcdedit.exe /set nointegritychecks on & ...

  10. json.dumps()包装中文字符串

    开发环境 系统: ubuntu18.04 系统编码: $LANG = en_US.UTF-8 python解释器版本: Python 3.6.7 乱码现场 使用 json.dumps() 将 dict ...