gpt4 book ai didi

mysql错误1451

转载 作者:可可西里 更新时间:2023-11-01 07:46:04 28 4
gpt4 key购买 nike

我有代码为 1451 的 mysql 错误。

Cannot delete or update a parent row: a foreign key constraint fails (online_store_admin.osa_admin_logs, CONSTRAINT fk_admins_logs FOREIGN 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');

当我使用这个语句时出现问题:

delete from osa_admins where aid='2';

我想我已经设置了“on delete cascade”。任何人都知道如何删除级联?所以我不需要手动删除 osa_admin_logs 数据。哦,我使用 innodb 作为数据库引擎(我有默认的 mysql)。

很抱歉,我问了同样有答案的问题,请告诉我在哪里可以得到我的问题。

谢谢。

最佳答案

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

SET foreign_key_checks = 0; 
DELETE FROM your_table_name WHERE your_condition;
SET foreign_key_checks = 1;

关于mysql错误1451,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4505624/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com