mysql 1005_MYSQL使用错误 MYSQL中ERROR 1005
在使用MYsql的時候,在操作不當時,很容易出現(xiàn) ERROR 1005 (HY000): Can't create table 這類錯誤。很多站長朋友可能需要排查很久才會找到問題的原因其實很簡單,希望這篇文章可以對站長朋友以及Mysql初學者一點幫助。
MYSQL官方提供的問題原因:
在信息中有一組【LATEST FOREIGN KEY ERROR】會有最近錯誤的詳細描述和解決辦法。
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.
(譯:不能在“被reference的表”里找到包含“被reference字段”的索引,或者是兩個關聯(lián)字段類型不匹配)
以下介紹兩個示例:
示例一:
create table booktype
(
btid?? int(5) unsigned zerofill auto_increment not null primary key,
btname varchar(100) not null unique,
btnote text
);
create table books
(
bid int(5) unsigned zerofill auto_increment not null primary key,
bname char(30) not null,
isbn char(50) not null,
author char(30) not null,
press?? text,
summary text,
bcount int not null default 0,
btid?? int,
foreign key(btid) references booktype(btid)
);
出現(xiàn)的報錯:
ERROR 1005 (HY000): Can't create table '.\bookdata\books.frm' (errno: 150)
主要問題以及解決辦法是:
foreign key(btid) references booktype(btid) 中books表的 btid?? 是int和booktype表中的btid設置的關聯(lián)字段類型不匹配,books表中btid改正成:btid?? int(5) unsigned zerofill ,就不會報錯了,創(chuàng)建表和修改表地時候常常一步小小就忘記了這個.
總結
以上是生活随笔為你收集整理的mysql 1005_MYSQL使用错误 MYSQL中ERROR 1005的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 4599元 佳能EOS R50正式开售:
- 下一篇: iQOO Neo8核心配置现身:首发高频