我只是使用MySQL Workbench得到这个错误,但是当我在控制台中手动导入它时(使用.sql文件的内容)然后它正常工作...问题是这个.sql文件是非常大,我不能在命令行中粘贴太多(chrome会崩溃等)..所以我必须使用MySQL Workbench ..
表:
CREATE TABLE list_countries (
country_code CHAR(2) NOT NULL,
country_name VARCHAR(45) NOT NULL,
PRIMARY KEY (country_code)
);
INSERT INTO list_countries (country_code, country_name) VALUES
('A1', 'Anonymous Proxy'),
('A2', 'Satellite Provider'),
('AD', 'Andorra');
CREATE TABLE list_ipv4 (
range_start INT UNSIGNED NOT NULL,
range_end INT UNSIGNED NOT NULL,
country_code CHAR(2) NOT NULL,
banned INT UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY (range_start, range_end, country_code),
CONSTRAINT fk_ipv4_countrycode
FOREIGN KEY (country_code)
REFERENCES list_countries (country_code)
ON DELETE RESTRICT
ON UPDATE RESTRICT
);
我试图用MySQL Workbench导入的.sql文件的内容(只有一些第一行):
INSERT INTO list_ipv4 (range_start, range_end, country_code) VALUES (16777216, 16777471, 'AU'),
(16777472, 16778239, 'CN'),
(16778240, 16779263, 'AU');
错误消息:第1行的错误1452(23000):无法添加或更新a 子行:外键约束失败(
samp
。list_ipv4
, 约束fk_ipv4_countrycode
外键(country_code
) 参考list_countries
(country_code
))exitcode 1的操作失败
请帮忙:/