Computing.Net > Forums > Database > setting a foreign key (MySQL 5.0)

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

setting a foreign key (MySQL 5.0)

Reply to Message Icon

Name: liliyaw
Date: March 30, 2006 at 11:48:25 Pacific
OS: linux
CPU/Ram: 524
Product: don't know
Comment:

Hello everyone,
I'd like to be able to mark one of the columns in table "table1" to be a foreign key from table "table2". Both tables are already populated with data. I'm using MySQL 5.0 So I'd like to do something like this:
ALTER TABLE table1 ADD FOREIGN KEY (column_to_modify) REFERENCES table2 (id) ON DELETE CASCADE ON UPDATE NO ACTION;

I get an error when I do this. I will appreciate any input, thank in advance.



Sponsored Link
Ads by Google

Response Number 1
Name: Guy
Date: April 9, 2006 at 10:04:28 Pacific
Reply:

Without the exact error message, this is just a guess.

Both columns (column_to_modify, id) must have *previously* built indexes on them.

I know that is a common mistake.

Guy


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Database Forum Home


Sponsored links

Ads by Google


Results for: setting a foreign key (MySQL 5.0)

Authentication Protocol MySQL 5.0? www.computing.net/answers/dbase/authentication-protocol-mysql-50-/8.html

Can't login to mysql www.computing.net/answers/dbase/cant-login-to-mysql/303.html

Finding top salespeople www.computing.net/answers/dbase/finding-top-salespeople/403.html