Zabbix数据库升级失败。无法添加或更新子行:外键约束失败

时间:2016-07-14 23:58:02

标签: mysql foreign-keys zabbix

更改了内容:

看起来Zabbix在数据库升级期间创建了一个TMP表,将原始表中的数据复制到TMP表,删除原始表,用Constraint创建一个新表,尝试将数据从tmp表复制到新表并失败。我删除了trigger_discovery表的对比,然后更新了,然后跳转到graph_discovery并失败了。我会重新添加约束,但为什么会失败以及需要做什么?

Zabbix LOGS:

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

1 个答案:

答案 0 :(得分:1)

Zabbix 2.2高达2.4

/var/log/zabbix-server/zabbix_server.log

[Z3005]查询失败:[1452]无法添加或更新子行:外键约束失败(zabbixgraph_discovery,CONSTRAINT c_graph_discovery_1 FOREIGN KEY({{1参考graphidgraphs)ON DELETE CASCADE)[插入graph_discovery(从graph_discovery_tmp中选择graphid,parent_graphid)]

graphid