Well, i have two tables
publica_evento_grupo
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
publica_identificacao_publicacao
Field | Type | Null | Key | Default | Extra
id_evento int(8) unsigned NO PRI
identificacao varchar(55) NO PRI
publica_evento_grupo.id_evento in is a foreign key to a third table called publica_evento but is also a foreign key together with the column to the table publica_identificacao_publicacao.identificacao. The problem is, I got to create the foreign key that relates publica_evento_grupo to publica_identificacao_publicacao by the key id_evento, but when I try to create the another FK with the column identificacao, it gives the errno below
[Err] 1005 - Can't create table '#sql-1049_1980992' (errno: 150).
As you can see the table publica_identificacao_publicacao has two PK and that iss the reason that it has to be 2 FK to relate them, i didn’t create the indexes yet, because as far as i know, i just have to create the indexes after adding the FK contraints, and I was able to create the FK contraint to the column id_evento between evento_grupo and identificacao_publicacao, i don’t know why just the column identificacao is giving this error
EDIT 1: @RolandBouman i don’t have the permission to use that command SHOW ENGINE INNODB STATUS
EDIT 2: @Geoff_Montee acctually the command you passed worked, to undestand why i use that structure take a look at this question MySQL UNIQUE Constraint multiple columns condition
That error usually happens because there is a type mismatch between the referring table and the referred table. In this case, the types seem to match.
Have you considered having a constraint for both fields in the primary composite key? You might have to remove the existing foreign key constraint on
id_eventofirst.It seems as though the error in this case might be because you try to add a foreign key constraint to only part of a composite primary key.
Does
identificacaoexist in any other tables? Why do you want to add a foreign key constraint to only part of a composite primary key?Think about it this way…
Let’s say you do have a foreign key constraint in the
publica_evento_grupotable to theidentificacaofield by itself. Let’s also say in thepublica_identificacao_publicacaotable you have(1, "some string")and(2, "some string"). So if you delete(2, "some string"), but leave(1, "some string")in its place. The rows that refer to(1, "some string")in thepublica_evento_grupotable will complain, even though they shouldn’t!So it sounds to me like you should add a foreign key constraint to all of a primary key or none of it.