小编Nat*_*han的帖子

为什么这个外键约束的形成不正确?

我是如何得出这个问题的,其本身就是一堆错误消息。

首先,这是错误消息1452: Cannot add or update a child row: a foreign key constraint fails

...尝试使用绝对有效的外键插入数据。

现在,我重新创建了表以重复问题并发现了一个新错误,这使我更接近根本原因。

Error Code: 1005. Can't create table `covers` (errno: 150 "Foreign key constraint is incorrectly formed")
Run Code Online (Sandbox Code Playgroud)

以下是表格:

CREATE TABLE IF NOT EXISTS `entities` (
  `id` BIGINT(20) NOT NULL AUTO_INCREMENT,
  `type` VARCHAR(255) NOT NULL,
  PRIMARY KEY (`id`)  )
ENGINE = InnoDB
AUTO_INCREMENT = 100001
PARTITION BY KEY() PARTITIONS 10 ;

CREATE TABLE IF NOT EXISTS `covers` (
  `id` BIGINT(20) NOT NULL,
  `title` VARCHAR(255) NOT …
Run Code Online (Sandbox Code Playgroud)

mysql sql mariadb

6
推荐指数
2
解决办法
4138
查看次数

标签 统计

mariadb ×1

mysql ×1

sql ×1