Skip to content
Advertisement

#1072 – Key column ‘role_id’ doesn’t exist in table

I am trying to add foreign key on my other table but this gave me error #1072 - Key column 'role_id' doesn't exist in table

I have created a table named role

then I created like this

then when I try to alter table on my user table

and I got an error like this

#1072 - Key column 'role_id' doesn't exist in table

Advertisement

Answer

You have to have the column you reference in add foreign key (role_id) inside your user table. Otherwise you get that error.

You would have to have inside your user table something like:

Or if you don’t have it, you have to do:

Before you set it as a foreign key.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement