当我尝试使用load data
命令将数据加载到我的MySQL(实际上是MariaDB)表时出现错误:
load data local infile '/tmp/my_data.tsv'
into table my_schema.my_table
fields terminated by '\t'
optionally enclosed by '"'
escaped by '\\'
lines terminated by '\n';
答案 0 :(得分:0)
出于某种原因,当您加载的数据破坏外键约束时,MySQL会给出这个模糊的错误消息(更详细地描述here)。
我设法通过直接从命令行执行load data
命令来获取正确的错误消息。 即正在运行:
mysql -u username -p --local-infile --execute= \
"load data local infile '/tmp/my_data.tsv' into table my_schema.my_table \
fields terminated by '\t' optionally enclosed by '\"' escaped by '\\\\';"
给出了错误消息:
Cannot add or update a child row: a foreign key constraint fails
(`my_schema`.`my_table`, CONSTRAINT `other_table` FOREIGN KEY
(`id`) REFERENCES `other_table` (`id`))
删除违反外键约束的行后,我能够导入我的数据。