Phpmyadmin

errno: 150 ‘外鍵約束格式不正確

  • December 9, 2021
create table Users(
id float(6) primary key,
username VARCHAR(20),
foreign key(id) references Emps(id));

/*inserting records into users table*/
insert into Users (id) select Employee_Id from emps limit 5;

select * from users;/*selecting records from users table*/

問題是

create table Users(
id float(6) primary key,
username VARCHAR(20),
foreign key(id) references Emps(id));
MySQL said: Documentation

#1005 - 無法創建表MidtermUsers(errno: 150 “外鍵約束格式不正確”)

為了使外鍵約束起作用,表中id列的類型需要與表中列的類型Users相同。Employee_Id``emps

例如,假設Employee_Idhas 類型int(11) unsigned,那麼您也應該指定idin的類型Users

(順便說一句,float(6)是一個奇怪的主/外鍵!)

引用自:https://dba.stackexchange.com/questions/303734