MYSQL ALTER Can't assign foreign key (errno: 150) -


i'm trying assign foreign key.

i have 'users' table:

user_id        mediumint(8) unsigned, notnull, primary key, autoincrement, first_name     varchar(20)          , notnull last_name      varchar(40)          , notnull 

and cetera. , have 'projects' table:

project_id          int(10) unsigned, notnull, primary key, autoincrement, project_name        varchar(20)     , notnull user_id             mediumint(8)    , notnull 

and i've learnt foreign keys, sound great, can't them work...

alter table projects  add constraint fk_projects  foreign key (user_id)  references users(user_id)  on update cascade  on delete cascade; 

returns error message:

error 1005 (hy000): can't create table 'thermal.#sql-62d9_4' (errno: 150)

what missing?

found it.

the problem 2 user_id columns not same type, in users "mediumint unsigned", while in projects "mediumint", not being entirely sure "unsignued" means didn't pick on this.

the solution change them:

alter table projects modify coulmn user_id mediumint unsigned; 

and ran command above, , worked.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -