Flask_SqlAlchemy 1215, 'Cannot add f oreign key constraint'
Flask_SqlAlchemy 1215, 'Cannot add f oreign key constraint'报错
sqlalchemy.exc.IntegrityError: (pymysql.err.IntegrityError) (1215, 'Cannot add f
oreign key constraint') [SQL: 'ALTER TABLE users ADD FOREIGN KEY(user_group) REF
ERENCES groups (id)']
解决:
使用如下命令查看报错信息
SHOW ENGINE INNODB STATUS
| InnoDB | |
=====================================
2016-11-28 14:15:30 18c4 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 31 seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: 33 srv_active, 0 srv_shutdown, 19178 srv_idle
srv_master_thread log flush and writes: 19211
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 45
OS WAIT ARRAY INFO: signal count 47
Mutex spin waits 19, rounds 237, OS waits 7
RW-shared spins 31, rounds 930, OS waits 31
RW-excl spins 5, rounds 214, OS waits 7
Spin rounds per wait: 12.47 mutex, 30.00 RW-shared, 42.80 RW-excl
------------------------
LATEST FOREIGN KEY ERROR
------------------------
2016-11-28 13:59:59 18c4 Error in foreign key constraint of table flask/#sql-69c
_30:
FOREIGN KEY(user_group) REFERENCES groups (id):
Cannot find an index in the referenced table where the
referenced columns appear as the first columns, or column types
in the table and the referenced table do not match for constraint.
Note that the internal storage type of ENUM and SET changed in
tables created with >= InnoDB-4.1.12, and such columns in old tables
cannot be referenced by such columns in new tables.
See http://dev.mysql.com/doc/refman/5.6/en/innodb-foreign-key-constraints.html
for correct foreign key definition.
----------------------------------------
END OF INNODB MONITOR OUTPUT
============================
|
+--------+------+---------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
根据错误提示:
cannot be referenced by such columns in new tables.
See http://dev.mysql.com/doc/refman/5.6/en/innodb-foreign-key-constraints.html for correct foreign key definition.
删除数据库内所有表
再执行
1.删除project内的migrations文件夹 2.python runserver.py db init 3.python runserver.py db migrate -m "write some words" 4.python runserver.py db upgrade
Flask_SqlAlchemy 1215, 'Cannot add f oreign key constraint'的更多相关文章
- MySQL添加foreign key时出现1215 Cannot add the foreign key constraint
引言: MySQL中经常会需要创建父子表之间的约束,这个约束是需要建立在主外键基础之上的,这里解决了一个在创建主外键约束过程中碰到的一个问题. mysql中添加外键约束遇到一下情况: cannot a ...
- MySQL添加外键时报错 ERROR 1215 (HY000): Cannot add foreign key constraint
1.数据类型 2.数据表的引擎 数据表 mysql> show tables; +------------------+ | Tables_in_market | +--------- ...
- mysql执行带外键的sql文件时出现mysql ERROR 1215 (HY000): Cannot add foreign key constraint的解决
ERROR 1215 (HY000): Cannot add foreign key constraint 最近在建表时遇到了这个错误,然后找了下找到了解决办法,记录下: 本来是要建两张表: 1 2 ...
- Laravel 5.5 迁移报错:General error: 1215 Cannot add foreign key constraint
问题 之前一直用的 Laravel 5.4,数据库也是直接写 sql 的,感觉可定制性更强,顺便锻炼下 sql.这次改用了 Laravel 5.5,索性用迁移建库试试,结果报错如下: SQLSTATE ...
- 异常处理:1215 - Cannot add foreign key constraint
最近在做新生入学系统,学生表中包括新生的班级,专业等信息,班级,专业就需要和班级表,专业表进行关联,但是在添加外键的过程中却出现了“Cannot add foreign key constraint” ...
- Error 'Cannot add or update a child row: a foreign key constraint fails故障解决
一大早的,某从库突然报出故障:SQL线程中断! 查看从库状态: mysql> show slave status\G Slave_IO_State: Waiting for master to ...
- insert时报Cannot add or update a child row: a foreign key constraint fails (`yanchangzichan`.`productstatusrecord`, CONSTRAINT `p_cu` FOREIGN KEY (`cid`) REFERENCES `customer` (`cid`))错误
mybatis在insert时报Cannot add or update a child row: a foreign key constraint fails (`yanchangzichan`.` ...
- IntegrityError at /admin/users/userprofile/add/ (1452, 'Cannot add or update a child row: a foreign key constraint fails (`mxonline`.`django_admin_log`, CONSTRAINT `django_admin_log_user_id_c564eba6_
报错现象 在执行 django 后台管理的时候添加数据导致 1452 错误 报错代码 IntegrityError at /admin/users/userprofile/add/ (1452, 'C ...
- Cannot add foreign key constraint @ManyToMany @OneToMany
最近在使用shiro做权限管理模块时,使用的时user(用户)-role(角色)-resource(资源)模式,其中user-role 是多对多,role-resource 也是多对多.但是在使用sp ...
随机推荐
- GCC的编译和安装 很好的资料
http://blog.csdn.net/yrj/article/details/492404 1.GCC的编译和安装2.预处理 #define 可以支持不定数量的参数. 例子如下: ...
- 将solr3.5整合到Tomcat6.x中
最近在学习Lucene,然后进入到solr中,没想到一开始,solr就给我来了这么困难的开头,希望万事开头难,以后可以顺利一点吧.记录下将solr3.5整合到Tomcat6.x中的过程,以及遇到的一个 ...
- js中return、return true、return false的区别
一.返回控制与函数结果, 语法为:return 表达式; 语句结束函数执行,返回调用函数,而且把表达式的值作为函数的结果 二.返回控制, 无函数结果,语法为:return; 在大多数情况下,为事件 ...
- xml学习篇(一)
转自:http://www.cnblogs.com/Jimmy009/archive/2012/06/18/2553722.html XML简介: 好了可以开始正式的学习了,在以前看一本计算机书籍,一 ...
- Quartz.Net任务调度框架
Quartz.Net是一个开源的任务调度框架,非常强大,能够通过简单的配置帮助我们定时具体的操作. 相对于我们用的线程里面while(true)然后sleep来执行某个操作,应该算的上是高端,大气,上 ...
- 基于开源 Openfire 聊天服务器 - 开发Openfire聊天记录插件[转]
上一篇文章介绍到怎么在自己的Java环境中搭建openfire插件开发的环境,同时介绍到怎样一步步简单的开发openfire插件.一步步很详细的介绍到简单插件开发,带Servlet的插件的开发.带JS ...
- [AngularJS + Webpack] ES6 with BabelJS
Install: npm install --save-dev babel-loader webpack.config.js: Add module, tell webpack to find all ...
- range() 函数创建并返回一个包含指定范围的元素的数组
语法 range(first,second,step) 参数 描述 first 必需.规定数组元素的最小值. second 必需.规定数组元素的最大值. step 可选.规定元素之间的步进制.默认是 ...
- Qt 学习之路:输入元素
前面的章节中,我们看到了作为输入元素的MouseArea,用于接收鼠标的输入.下面,我们再来介绍关于键盘输入的两个元素:TextInput和TextEdit. TextInput是单行的文本输入框,支 ...
- MapReduce优化
Combiner和Partitioner是用来优化MapReduce的,可以提高MapReduce的运行效率.下面我们来具体学习这两个组件 Combiner 我们以WordCount为例,首先通过下面 ...