mysq添加外键报错:check the manual that corresponds to your MySQL server version for the right syntax to us

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysq添加外键报错:check the manual that corresponds to your MySQL server version for the right syntax to us相关的知识,希望对你有一定的参考价值。

今天用navcat往一个表添加外键的时候报错:

You have an error in your SQL syntax; check the manual that corresponds to your mysql server version for the right syntax to use near ‘TYPE=InnoDB‘ at line 1

排查之后发现是因为两个表的类型不一样所致:

 SQL:SHOW TABLE STATUS 查询出数据表的状态,Engine那一列就是

技术分享

 

 使用语句修改表类型:ALTER TABLE `cms_channel` ENGINE = INNODB;

问题解决

===============================================================

 

顺便给出添加外键的sql语句:

alter table 表名 add constraint FK_ID foreign key(你的外键字段名) REFERENCES 外表表名(对应的表的主键字段名);

例子:

alter table cms_article add constraint FK_ARTICLE_DEPT_1 foreign key(dept_id) REFERENCES sys_department(id);

 

用这个语句运行的时候不会报错,客户端也会提示功能修改了多少条数据,但是重新查询数据库表结构的时候发现修改不成功,因为表类型不一样是不能建立外键的

 

以上是关于mysq添加外键报错:check the manual that corresponds to your MySQL server version for the right syntax to us的主要内容,如果未能解决你的问题,请参考以下文章

MySQL sql 报错 You have an error in your SQL syntax; check the manual that corresponds to your MySQ

MySQL设置外键报错 #1452 - Cannot add or update a child row: a foreign key constraint fails 解决方法

MyBatis批量插入返回主键报错

pip install报错,“Consider using the `--user` option or check the permissions”

Failed to check the status of the service报错解决

nagios配置pnp4nagios报错“Please check the documentatio