我在數據庫中創建兩個表錯誤SQL:不能添加或更新子行,外鍵約束失敗
CREATE TABLE ratables (
id int(11) NOT NULL auto_increment,
ratableKey varchar(50) NOT NULL,
created_at timestamp NOT NULL default CURRENT_TIMESTAMP,
) AUTO_INCREMENT=1 ;
和
CREATE TABLE ratings (
id int(11) NOT NULL auto_increment,
ratable_id int(11) NOT NULL,
ip_address varchar(50) NOT NULL,
rating int(11) NOT NULL,
timestamp timestamp NOT NULL default CURRENT_TIMESTAMP,
PRIMARY KEY (id),
CONSTRAINT rabid_ratings_fk FOREIGN KEY (ratable_id) REFERENCES
ratables(id)
) AUTO_INCREMENT=1 ;
當我試圖插入
INSERT INTO ratings(ratable_id, ip_address, rating) VALUES ('9', 'ip_adresse', 'rating');
它給了我這個錯誤
Cannot add or update a child row: a foreign key constraint fails (bd_pagespro.ratings, CONSTRAINT rabid_ratings_fk FOREIGN KEY (ratable_id) REFERENCES ratables(id))
請幫忙!
根據所使用的非標準語法添加了'mysql'標記。 – 2014-09-24 16:07:20
你需要在表格中使用id = 9的記錄。 – 2014-09-24 16:07:36
@a_horse_with_no_name:所有數據庫在某處都有非標準語法。 – siride 2014-09-24 18:21:01