List:General Discussion« Previous MessageNext Message »
From:Abhishek Choudhary Date:March 21 2013 4:43pm
Subject:Re: Foreign key on multiple columns
View as plain text  
>      CREATE TABLE test2 (
>        ID INT NOT
> NULL AUTO_INCREMENT,
>        col1 INT NOT NULL,
>   
>     col2 INT NOT NULL,
>        PRIMARY KEY
> (ID),
>        CONSTRAINT fk FOREIGN KEY (col1, col2)
> 
>                     REFERENCES test1(ID,
> ID)
>        ON UPDATE CASCADE
>        ON
> DELETE RESTRICT
>      ) ENGINE=InnoDB;


i think error is because of
> referencing the same column in test1 table (ID,ID) .
try to change the column name 
> then run the code hope ur problem will solve out .

Abhishek
> choudhary,
www.tech4urhelp.blogspot.com




----- Original Message -----
From: Peter
> Brawley <peter.brawley@stripped>
To: mysql@stripped
Cc: 
Sent: Thursday,
> 21 March 2013 8:14 PM
Subject: Re: Foreign key on multiple columns

On 2013-03-21 8:12 AM,
> Norah Jones wrote:
> I'm trying to create a foreign key on two columns but getting error...
>
> Here's what I tried:
>
>      CREATE TABLE test2 (
>   
>     ID INT NOT NULL AUTO_INCREMENT,
>        col1 INT NOT
> NULL,
>        col2 INT NOT NULL,
>       
> PRIMARY KEY (ID),
>        CONSTRAINT fk FOREIGN KEY (col1,
> col2)
>                     
> REFERENCES test1(ID, ID)
>        ON UPDATE CASCADE
> 
>       ON DELETE RESTRICT
>      ) ENGINE=InnoDB;
>
> But I get `ERROR 1005 (HY000): Can't create table 'DB.test2' (errno: 150)`

Dupe reference
> column.

PB
>
>


-- 
MySQL General Mailing List
For list archives:
> http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/mysql
Thread
Foreign key on multiple columnsNorah Jones21 Mar
  • Re: Foreign key on multiple columnsPeter Brawley21 Mar
    • Re: Foreign key on multiple columnsAbhishek Choudhary21 Mar
      • Re: Foreign key on multiple columnsshawn green21 Mar