mysql错误1451

cra*_*mob 3 mysql mysql-error-1451

我有代码1451的mysql错误.

无法删除或更新父行:外键约束失败(online_store_admin.osa_admin_logs,CONSTRAINT fk_admins_logsFOREIGN KEY(aid)REFERENCES osa_admins(aid))

这里是sql语句:


drop table if exists osa_admins;
create table if not exists osa_admins(
 aid int unsigned not null auto_increment, 
 uid varchar(50) not null, 
 pass char(41) not null, 
 erp_id int unsigned not null, 
 last_login int unsigned not null,
 is_block tinyint unsigned not null,
 menus varchar(50) not null,
 is_login tinyint unsigned not null,
 ip_login char(15) not null,

 constraint idx_osa_admins primary key using btree(aid)
);
insert into osa_admins value
(NULL, 'root', password('6789'), '0', '0', '0', '*', '0', '127.000.000.001'),
(NULL, 'ryu', password('6789'), '0', '0', '0', '*', '0', '127.000.000.001');

drop table if exists osa_admin_logs;
create table if not exists osa_admin_logs(
 lid bigint unsigned not null,
 aid int unsigned not null,
 dates int unsigned not null,
 logs text not null,

 constraint idx_osa_admin_logs primary key using btree(lid),
 constraint fk_admins_logs foreign key (aid)
  references osa_admins(aid)
  match full
  on update cascade
  on delete cascade
);
insert into osa_admin_logs values
(NULL, '2', '0', 'some action here'),
(NULL, '2', '0', 'again, some action here');

当我使用这个陈述时出现问题:

从osa_admins删除,其中aid ='2';

我想我已经设置了"删除级联".有谁知道如何删除级联?所以我没有必要手动检测osa_admin_logs数据.哦,我使用innodb作为数据库引擎(我有默认的mysql).

对不起,我问同样的问题有答案,请告诉我在哪里可以得到我的问题.

谢谢.

Ksh*_*tiz 12

使用以下命令执行此操作:

SET foreign_key_checks = 0; 
DELETE FROM your_table_name WHERE your_condition;
SET foreign_key_checks = 1;
Run Code Online (Sandbox Code Playgroud)


The*_*ter 7

match full从约束中删除

使用显式MATCH子句不会产生指定的效果,并且还会导致忽略ON DELETE和ON UPDATE子句.出于这些原因,应该避免指定MATCH.

MySql docs http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html