小编Ben*_*Ben的帖子

MySQL,外键,无法创建表错误 150

更新:抱歉,这是因为我忘记将 UNSIGNED 属性添加到 lang_id 列。

原文:我正在尝试在 MySQL 中创建一个带有外键的表。

我收到此错误:#1005 - 无法创建表 'xy.trans' (errno: 150)

以下创建语句有什么问题吗?

CREATE  TABLE IF NOT EXISTS `lang` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `code` CHAR(2) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE = InnoDB;


CREATE  TABLE IF NOT EXISTS `trans` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `something` TEXT NOT NULL,
  `lang_id` INT NULL,
  PRIMARY KEY (`id`),
  INDEX `index_trans_lang` (`lang_id` ASC),
  CONSTRAINT `fk_trans_lang`
    FOREIGN KEY (`lang_id` )
    REFERENCES `lang` (`id` )
    ON DELETE SET NULL …
Run Code Online (Sandbox Code Playgroud)

mysql foreign-key

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

foreign-key ×1

mysql ×1