我收到以下错误:
ERROR 1215 (HY000) at line 13: Cannot add foreign key constraint
对于以下查询:
ALTER TABLE client_generique
ADD CONSTRAINT client_generique_boutique_id_boutique_id
FOREIGN KEY (boutique_id) REFERENCES boutique (id)
ON DELETE SET NULL;
boutique.id
是一个主键,唯一且不为空
。
精品表的phpmyadmin结构导出是这样的:
--
-- Table structure for table `boutique`
--
CREATE TABLE `boutique` (
`id` bigint(20) NOT NULL,
`nom` varchar(255) NOT NULL,
`identifiant_site` varchar(8) NOT NULL COMMENT 'the eight number identifier from the bank',
`certificate` varchar(255) NOT NULL COMMENT 'changes according to the mode, this will be used as salt in the sha1 that will be sent to the bank as the ''signature''',
`mode` varchar(10) NOT NULL COMMENT 'is the ''vads_ctx_mode'': TEST or PRODUCTION',
`payment_system` varchar(10) NOT NULL COMMENT 'CYBERPLUS OR PAYZEN for the new payment system added in end 2014'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Indexes for table `boutique`
--
ALTER TABLE `boutique`
ADD PRIMARY KEY (`id`),
ADD UNIQUE KEY `unique_mode_per_identifiant_idx` (`identifiant_site`,`mode`);
我不明白。是什么原因?如何解决这个问题?
最佳答案
是否您的表 client_generique
在 boutique_id
中存储了表 boutique
中不存在的值?
由于您尝试建立对 boutique
的引用,因此值必须存在于该表中。
关于mysql - 错误 1215 (HY000) 在第 13 行 : Cannot add foreign key constraint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36886580/