![](/img/trans.png)
[英]IntegrityError (1452, 'Cannot add or update a child row: a foreign key constraint fails)
[英]_mysql_exceptions.IntegrityError: (1215, 'Cannot add foreign key constraint')
我使用 Ontonotes DB 工具,但遇到问题。
我阅读了它的文档,它说这个工具在 mysql 5.0 上运行良好。 但是,我找不到这个版本。 所以,我安装了 mysql 5.7。 出现这个问题,问题是这样的:
python on/tools/init_db.py --init ontonotes localhost root ontonotes-release-4.0/
正在初始化数据库...
/Users/anaconda/lib/python2.7/site-packages/on/ INIT的.py:525:警告:未知表'ontonotes.tree' cursor.execute( “” “下降如果存在%s的表;” “” % thing.sql_table_name)
create table tree
(
id varchar(255) not null collate utf8_bin primary key,
parent_id varchar(255),
document_id varchar(255),
word varchar(255),
child_index int,
start int not null,
end int not null,
coref_section int not null,
syntactic_link_type varchar(255),
tag varchar(255) not null,
part_of_speech varchar(255),
phrase_type varchar(255),
function_tag_id varchar(255),
string longtext,
no_trace_string longtext,
parse longtext,
foreign key (parent_id) references tree.id,
foreign key (document_id) references document.id,
foreign key (syntactic_link_type) references syntactic_link_type.id,
foreign key (part_of_speech) references pos_type.id,
foreign key (phrase_type) references phrase_type.id,
foreign key (function_tag_id) references compound_function_tag.id
)
default character set utf8;
回溯(最近一次调用):文件“on/tools/init_db.py”,第 81 行,在 on.ontonotes.initialize_db(a_cursor) 文件“/Users/anaconda/lib/python2.7/site-packages/on/ init .py”,第 528 行,在 initialize_db cursor.execute(thing.sql_create_statement) 文件“/Users/anaconda/lib/python2.7/site-packages/MySQLdb/cursors.py”,第 205 行,在执行 self.errorhandler (self, exc, value) 文件 "/Users/anaconda/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler raise errorclass, errorvalue _mysql_exceptions.IntegrityError: (1215, 'Cannot add外键约束')
并且已经创建了三个表:
create table ontonotes
(
id varchar(255) not null primary key
)
default character set utf8;
create table subcorpus
(
id varchar(255) not null primary key,
base_dir varchar(255) not null,
top_dir varchar(255) not null,
root_dir varchar(255) not null,
language_id varchar(255) not null,
encoding_id varchar(255) not null,
ontonotes_id varchar(255) not null
)
default character set utf8;
create table file
(
id varchar(255) not null primary key,
base_dir varchar(255) not null,
physical_filename varchar(255) not null,
document_id varchar(255) not null,
file_type varchar(255) not null,
subcorpus_id varchar(255) not null
)
default character set utf8;
我真的不知道如何解决这个问题,因为我对mysql不熟悉。 有人可以帮助我,或者给我一个 mysql 5.0 版本(linux 64bit/mac 64bit)? 很想你!
onnotes 作者选择 myisam 作为引擎,忽略 fks。 他们将它们留在模式定义中,因为
“即使 MyISAM 忽略外键约束,我们也确实将它们包含在 table create 语句中以记录它们”。 第10页,官方Ontonnotes-v5工具文档
如果您使用,例如 innodb,这是一个问题。 所以答案是:要么使用 myisam,要么从所有模式定义中删除 fk 约束。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.