Quantcast
Channel: MySQL Forums - InnoDB
Viewing all articles
Browse latest Browse all 1954

alter table foreign key syntax error (1 reply)

$
0
0
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.

Viewing all articles
Browse latest Browse all 1954

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>