Hi,
I have two problems when I tried to modify a column to foreign key reference, appreciate helps:
1. Change to foreign key
I have two tables both have an identical column provider_id tinyint(8) unsigned. I want to change one table as a foreign key reference to another, but failed:
mysql> alter table Consumer add foreign key (provider_id) references Supply (provider_id) ON UPDATE CASCADE ON DELETE CASCADE;
ERROR 1005 (HY000): Can't create table 'MyDatabase.#sql-fa2_26346' (errno: 150)
2. Add ON DELETE CASCADE
I have a table group_map which has already created by a foreign key, but without ON DELETE CASCADE, how can I add the "ON DELETE CASCADE" to it?
mysql> alter table group_map add foreign key (user_id) references Users(id) ON UPDATE CASCADE ON DELETE CASCADE;
ERROR 1005 (HY000): Can't create table 'MyDatabase.#sql-fa2_26346' (errno: 150)
Thank you.
I have two problems when I tried to modify a column to foreign key reference, appreciate helps:
1. Change to foreign key
I have two tables both have an identical column provider_id tinyint(8) unsigned. I want to change one table as a foreign key reference to another, but failed:
mysql> alter table Consumer add foreign key (provider_id) references Supply (provider_id) ON UPDATE CASCADE ON DELETE CASCADE;
ERROR 1005 (HY000): Can't create table 'MyDatabase.#sql-fa2_26346' (errno: 150)
2. Add ON DELETE CASCADE
I have a table group_map which has already created by a foreign key, but without ON DELETE CASCADE, how can I add the "ON DELETE CASCADE" to it?
mysql> alter table group_map add foreign key (user_id) references Users(id) ON UPDATE CASCADE ON DELETE CASCADE;
ERROR 1005 (HY000): Can't create table 'MyDatabase.#sql-fa2_26346' (errno: 150)
Thank you.