Mur*_*ilo 1 mysql sql indexing entity-relationship foreign-key-relationship
好吧,我有两张桌子
Field | Type | Null | Key | Default | Extra
id_evento_grupo int(10) unsigned NO PRI auto_increment
id_evento int(8) unsigned NO MUL
id_grupo int(8) unsigned NO MUL
identificacao varchar(55) NO
Run Code Online (Sandbox Code Playgroud)
Field | Type | Null | Key | Default | Extra
id_evento int(8) unsigned NO PRI
identificacao varchar(55) NO PRI
Run Code Online (Sandbox Code Playgroud)
publica_evento_grupo.id_eventoin是第三个名为publica_evento的表的外键,但也是表的列的外键publica_identificacao_publicacao.identificacao.问题是,我必须通过密钥创建将publica_evento_grupo与publica_identificacao_publicacao相关联的外键id_evento,但是当我尝试使用该列创建另一个FK时identificacao,它会给出下面的errno
[Err] 1005 - Can't create table '#sql-1049_1980992' (errno: 150).
Run Code Online (Sandbox Code Playgroud)
正如你可以看到表publica_identificacao_publicacao有两个PK,并且它必须是2 FK来关联它们的原因,我还没有创建索引,因为据我所知,我只需要在之后创建索引添加FK 约束,我能够id_evento在evento_grupo和identificacao_publicacao之间的列创建FK 约束,我不知道为什么只是列identificacao给出了这个错误
编辑1:@RolandBouman我没有权限使用该命令SHOW ENGINE INNODB STATUS
编辑2:@Geoff_Montee实际上你传递的命令工作,以解决为什么我使用该结构看看这个问题MySQL UNIQUE Constraint多列条件
如果没有实际的DDL,就不那么容易说了.我建议做:
SHOW ENGINE INNODB STATUS;
Run Code Online (Sandbox Code Playgroud)
在您遇到此错误后立即.在输出中,查找如下所示的部分:
------------------------
LATEST FOREIGN KEY ERROR
------------------------
121026 22:40:18 Error in foreign key constraint of table test/#sql-154c_94:
foreign key(rid) references bla(id):
Cannot find an index in the referenced table where the
referenced columns appear as the first columns, or column types
in the table and the referenced table do not match for constraint.
Note that the internal storage type of ENUM and SET changed in
tables created with >= InnoDB-4.1.12, and such columns in old tables
cannot be referenced by such columns in new tables.
See http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html
for correct foreign key definition.
Run Code Online (Sandbox Code Playgroud)
您将在那里找到有关外键定义有什么问题的详细信息.
| 归档时间: |
|
| 查看次数: |
3857 次 |
| 最近记录: |