#1217 - 无法删除或更新父行:PHPMyAdmin 中的外键约束失败
#1217 - Cannot delete or update a parent row: a foreign key constraint fails in PHPMyAdmin
我正在尝试在 PHPMyAdmin
中创建数据库,但在创建 table 后出现错误 #1217 - Cannot delete or update a parent row: a foreign key constraint fails
。我的代码是
drop table if exists tbl;
create table tbl(
name varchar(20) primary key,
pword char(30) not null,
mail varchar(50) not null
);
而且我已经在 MySQL Workbench
中尝试过了,它在运行时根本没有给我任何错误
编辑
我的另一个 table 引用 tbl
table 是
create table tbl2(
tbl2_id int not null auto_increment,
name varchar(20),
primary key (tbl2_id),
foreign key (name) references tbl(name)
);
该错误意味着有来自另一个 table 的外键引用了您的 tbl
table 的一行。如果另一个 table 引用了一个 table,则您无法删除它,这意味着您的 table 之一具有引用 table 的外键不存在了。
这就是foreign key constraint fails
的意思
我正在尝试在 PHPMyAdmin
中创建数据库,但在创建 table 后出现错误 #1217 - Cannot delete or update a parent row: a foreign key constraint fails
。我的代码是
drop table if exists tbl;
create table tbl(
name varchar(20) primary key,
pword char(30) not null,
mail varchar(50) not null
);
而且我已经在 MySQL Workbench
中尝试过了,它在运行时根本没有给我任何错误
编辑
我的另一个 table 引用 tbl
table 是
create table tbl2(
tbl2_id int not null auto_increment,
name varchar(20),
primary key (tbl2_id),
foreign key (name) references tbl(name)
);
该错误意味着有来自另一个 table 的外键引用了您的 tbl
table 的一行。如果另一个 table 引用了一个 table,则您无法删除它,这意味着您的 table 之一具有引用 table 的外键不存在了。
这就是foreign key constraint fails
的意思