错误1005(HY000):无法创建表(错误号:150) [英] ERROR 1005 (HY000): Can't create table (errno: 150)

查看:92
本文介绍了错误1005(HY000):无法创建表(错误号:150)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在mysql中创建表时出现错误.

I get an error when I try to create a table in 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)
);

错误:

ERROR 1005 (HY000): Can't create table 'posinventory.stock_in' (errno: 150)

推荐答案

查看有关

如果重新创建已删除的表,则该表必须具有定义 符合引用它的外键约束.它必须 具有正确的列名和类型,并且必须在 引用的键,如前所述.如果不满意,MySQL 返回错误号1005,并在错误中引用错误150 消息.

If you re-create a table that was dropped, it must have a definition that conforms to the foreign key constraints referencing it. It must have the right column names and types, and it must have indexes on the referenced keys, as stated earlier. If these are not satisfied, MySQL returns error number 1005 and refers to error 150 in the error message.

一些想法:

  • 更好地删除表并使用格式正确的语法来创建新表.
  • 确保将ENGINE=InnoDB;添加到CREATE TABLE-命令中.
  • 确保在您的MySQL服务器上启用了InnoDB.要验证这一点,请尝试以下命令:SHOW VARIABLES LIKE 'have_innodb';-如果返回YES,则启用InnoDB.
  • 检查您的命令中表名和字段名中的大小写.
  • 不仅要检查要创建的表,还要检查外键所引用的表.
  • 确保您引用的表已正确索引.
  • Better drop the tables and create it new with a well formed syntax.
  • Make sure to add ENGINE=InnoDB; to your CREATE TABLE - command.
  • Make sure InnoDB is enabled on your MySQL server. To verify this, try this command: SHOW VARIABLES LIKE 'have_innodb'; - if it returns a YES, then InnoDB is enabled.
  • Check your command for upper- and lowercases in table- and fieldnames.
  • Check this not only one the table you want to create, but also on the tables the foreign keys are referring to.
  • Make sure your referred tables are properly indexed.

这篇关于错误1005(HY000):无法创建表(错误号:150)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆