MySQL Forums
Forum List  »  InnoDB

problem adding foreign key...
Posted by: Albert Mata
Date: October 03, 2008 06:01AM

In TABLE1 there is a field called VLO_COD_ACC (varchar(6)).

In TABLE2 the first two fields are...
ste_int varchar(6)
ste_id smallint(5) unsigned auto_increment
...both are not null and primary key.

I'm trying to add a foreign key this way:

alter table TABLE1 add foreign key(VLO_COD_ACC) references TABLE2(ste_int);

But I get an error and when I take a look at SHOW ENGINE INNODB STATUS; I can see this:

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.

Which in my opinion isn't true at all as there is an index in the referenced table where the referenced column (ste_int) appear as the first column and column types are both times varchar(6).

Does anyone know what's wrong with it?

Many thanks in advance.

Options: ReplyQuote


Subject
Views
Written By
Posted
problem adding foreign key...
15350
October 03, 2008 06:01AM
6265
October 03, 2008 07:55AM
4496
October 16, 2008 12:13PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.