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