当我尝试在mysql中创建表时出现错误.
解决它的任何提示?
create table stock_in(
ind int not null auto_increment,
itemcode varchar(10) not null,
quantity int not null,
description text not null,
sales_ref int not null default -1,
return_outwards_ref int not null default -1,
stock_in_receipt_ref int not null default -1,
date text not null,
time text not null,
username text not null,
foreign key (sales_ref) references sales (receiptno),
foreign key (return_outwards_ref) references returnoutwards(ind),
primary key (ind)
);
Run Code Online (Sandbox Code Playgroud)
错误:
ERROR 1005 (HY000): Can't create table 'posinventory.stock_in' (errno: 150)
Run Code Online (Sandbox Code Playgroud)
Bjo*_*ern 29
查看有关外键约束的MySQL手册:
如果重新创建已删除的表,则它必须具有符合引用它的外键约束的定义.它必须具有正确的列名和类型,并且必须在引用的键上具有索引,如前所述.如果不满足这些,MySQL将返回错误号1005并在错误消息中引用错误150.
一些想法:
ENGINE=InnoDB;
到您的CREATE TABLE
- 命令.SHOW VARIABLES LIKE 'have_innodb';
- 如果返回YES,则启用InnoDB.小智 5
有完全一样的问题。它的来源是外键和引用的类型。
外键:
fer_id SMALLINT NOT NULL
Run Code Online (Sandbox Code Playgroud)
和原点字段(我们提供的参考):
id INT(11) UNSIGNED NOT NULL
Run Code Online (Sandbox Code Playgroud)
我也将fer_id INT(11)也设为未签名。神奇的作品!