mysq添加外键报错:check the manual that corresponds to your MySQL server version for the right syntax to use near 'TYPE=InnoDB' at line 1


今天用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);

 

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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



猜您在找 MySQL 8.0:check the manual that corresponds to your MySQL server version for the right syntax to use near 'identified by 'password'' at line 1 check the manual that corresponds to your MySQL server version for the right syntax to use near 'IDENTIFIED BY '123456' WITH GRANT OPTION' at line 1 【异常】MySQL建表报错: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 '"order"' at line 1 Django进行数据迁移时,报错:(1064, "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 '(6) NOT NULL)' at line 1") check the manual that corresponds to your MySQL server version for the right syntax to use near '(0) NULL DEFAULT NULL COMMENT check the manual that corresponds to your MySQL server version for the right syntax to use near check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc 解决:[Err] 1064 - 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 SQL语句报错:You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 1064 - 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 'groups)VALUES('1','hh','hh@163.com','Boss')' at line 1
 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM