我得到以下錯誤:ERROR 1215(HY000):無法添加外鍵約束
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
是primary key unique not null
。
精品表的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`);
我不明白。是什麼原因?如何解決這個問題呢?
使用清晰的句子是非常有用的,它不是你的學校練習冊。 – peterh