List:Community« Previous MessageNext Message »
From:Norah Jones Date:March 21 2013 1:12pm
Subject:Foreign key on multiple columns
View as plain text  
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)`



Thread
Foreign key on multiple columnsNorah Jones21 Mar
  • Re: Foreign key on multiple columnsArjen Lentz22 Mar