1

I tried to create the following table:

CREATE TABLE `updates` (
`update_id` INT(11) AUTO_INCREMENT ,
`update` VARCHAR(45),
`user_id_fk` VARCHAR(45),
`created` INT(11) ,
`ip` VARCHAR(45),
PRIMARY KEY (`update_id`),
FOREIGN KEY (user_id_fk) REFERENCES users(user_id));

Phpmyadmin shown error as

#1005 - Can't create table 'friends.updates' (errno: 150) (Details...)

When I click on 'Details' I get:

InnoDB Documentation Supports transactions, row-level locking, and foreign keys [ Variables | Buffer Pool | InnoDB Status ]

Please help me to overcome with this error.

vhu
  • 12,244
  • 11
  • 38
  • 48

2 Answers2

2

It seems user_id field data type in users table is int while here you are creating relation with varchar(45).

For foreign keys data type should be same, so keep it as was in users table.

Zafar Malik
  • 6,734
  • 2
  • 19
  • 30
1

If the error message refers to error 150, table creation failed because a foreign key constraint was not correctly formed. If the error message refers to error −1, table creation probably failed because the table includes a column name that matched the name of an internal InnoDB table.

Ref::http://dev.mysql.com/doc/refman/5.0/en/innodb-error-codes.html

also you can refer this link

Error Code: 1005. Can't create table '...' (errno: 150)

Community
  • 1
  • 1
scott
  • 3,112
  • 19
  • 52
  • 90