I ran the following query in MySQL command line and the tables were created. But when I ran in XAMPP, I got an error “1005 – Can’t create table ‘zoneboard.work’ (errno: 150)”
My query is :
Create Table user (
id_user INT (50)NOT NULL AUTO_INCREMENT ,
email VARCHAR( 64 ) NOT NULL ,
username VARCHAR( 16 ) NOT NULL ,
password VARCHAR( 32 ) NOT NULL ,
PRIMARY KEY ( id_user )
) ENGINE = InnoDB
CREATE TABLE work (
id_user INT( 50 ) NOT NULL AUTO_INCREMENT ,
task VARCHAR( 50 ) NOT NULL ,
comments VARCHAR( 100 ) NOT NULL ,
assignee VARCHAR( 16 ) NOT NULL ,
priority VARCHAR( 50 ) NOT NULL ,
status VARCHAR( 50 ) NOT NULL ,
dataum1 VARCHAR( 50 ) NOT NULL ,
dataum2 VARCHAR( 50 ) NOT NULL ,
PRIMARY KEY ( id_user ),
FOREIGN KEY(assignee) REFERENCES user(username)
) ENGINE = InnoDB
Parent table-user should have an index column(Here username should be indexed).
Refer: http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html