更改内容:
看起来Zabbix在数据库升级期间创建了一个TMP表,将数据从原始表复制到TMP表,删除原始表,使用约束创建一个新表,尝试将数据从tmp表复制到新表并失败了。我删除了trigger_discovery表的对比,它被更新,然后它跳转到graph_discovery并失败。我将重新添加约束,但为什么会失败以及需要做什么?
Zabbix 日志:
query: [create table graph_discovery_tmp (graphid bigint unsigned not null,parent_graphid bigint unsigned not null) engine=innodb]
query: [update dbversion set mandatory=2030012,optional=2030012]
query: [insert into graph_discovery_tmp (select graphid,parent_graphid from graph_discovery)]
query: [update dbversion set mandatory=2030013,optional=2030013]
query: [drop table graph_discovery]
query: [update dbversion set mandatory=203001,optional=203001]
query: [create table graph_discovery (graphid bigint unsigned not null,parent_graphid bigint unsigned not null,primary key (graphid)) engine=innodb]
query: [update dbversion set mandatory=2030015,optional=2030015]
query: [create index graph_discovery_1 on graph_discovery (parent_graphid)]
query: [ update dbversion set mandatory=2030016,optional=2030016]
query: [alter table graph_discovery add constraint c_graph_discovery_1 foreign key (graphid) references graphs (graphid) on delete cascade]
query: [update dbversion set mandatory=2030017,optional=2030017]
query: [alter table graph_discovery add constraint c_graph_discovery_2 foreign key (parent_graphid) references graphs (graphid)]
query: [update dbversion set mandatory=2030018,optional=2030018]
query: [insert into graph_discovery (select graphid,parent_graphid from graph_discovery_tmp)]
query failed: [1452] Cannot add or update a child row: a foreign key constraint fails (`zabbix`.`graph_discovery`, CONSTRAINT `c_graph_discovery_1` FOREIGN KEY (`graphid`) REFERENCES `graphs` (`graphid`) ON DELETE CASCADE) [insert into graph_discovery (select graphid,parent_graphid from graph_discovery_tmp)]
query: [insert into graph_discovery (select graphid,parent_graphid from graph_discovery_tmp)] failed, setting transaction as failed
database upgrade failed
End of DBcheck_version():FAIL
最佳答案
Zabbix 2.2 至 2.4
/var/log/zabbix-server/zabbix_server.log
[Z3005]查询失败:[1452]无法添加或更新子行:外键约束失败(zabbix
.graph_discovery
,CONSTRAINT c_graph_discovery_1
外键 (graphid
) 引用 graphs
(graphid
) 删除级联) [插入 graph_discovery (从 graph_discovery_tmp 中选择 graphid,parent_graphid) ]
use zabbix;
DROP TABLE graph_discovery;
CREATE TABLE `graph_discovery` (
`graphid` bigint unsigned NOT NULL,
`parent_graphid` bigint unsigned NOT NULL,
PRIMARY KEY (graphid)
) ENGINE=InnoDB;
关于mysql - Zabbix 数据库升级失败。无法添加或更新子行: a foreign key constraint fails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38385959/