简体   繁体   English

在mysql集群中创建表时出错

[英]Error while creating a table in mysql cluster

I'm trying to create a table in MySQL Cluster .我正在尝试在 MySQL Cluster 中创建一个表。 but getting a error while executing below query.但是在执行以下查询时出错。

CREATE TABLE `tbl_anal_results` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `tbl_bill_bill_id` int(10) unsigned NOT NULL,
  `item` varchar(256) NOT NULL,
  `bill_value` decimal(10,2) NOT NULL,
  `calc_value` decimal(10,2) NOT NULL,
  `err` tinyint(1) NOT NULL,
  `error_code` varchar(256) DEFAULT NULL,
  `tbl_bill_info_id` int(10) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_tbl_anal_results_tbl_bill1_idx` (`tbl_bill_bill_id`),
  CONSTRAINT `fk_tbl_anal_results_tbl_bill1` FOREIGN KEY (`tbl_bill_bill_id`) REFERENCES `tbl_bill` (`bill_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=ndbcluster AUTO_INCREMENT=16570225 DEFAULT CHARSET=latin1;

ERROR 1215 (HY000): Cannot add foreign key constraint ERROR 1215 (HY000): 无法添加外键约束

I have used same query which I used to create same table in old mysql setup.我使用了与在旧 mysql 设置中创建相同表的相同查询。 and I have changed ENGINE as ENGINE=ndbcluster instead of ENGINE=InnoDB我已将 ENGINE 更改为 ENGINE=ndbcluster 而不是 ENGINE=InnoDB

also noticed UPDATE CASCADE not working in mysql cluster.还注意到 UPDATE CASCADE 在 mysql 集群中不起作用。

Cut from docs: ON UPDATE CASCADE is not supported when the reference is to the parent table's primary key.从文档中截取:当引用是父表的主键时,不支持 ON UPDATE CASCADE。

This is because an update of a primary key is implemented as a delete of the old row (containing the old primary key) plus an insert of the new row (with a new primary key).这是因为主键的更新是通过删除旧行(包含旧主键)加上插入新行(带有新主键)来实现的。 This is not visible to the NDB kernel, which views these two rows as being the same, and thus has no way of knowing that this update should be cascaded.这对 NDB 内核是不可见的,它认为这两行是相同的,因此无法知道这个更新应该是级联的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM