MySQL Forums
Forum List  »  Newbie

foreign key usage....what's wrong?
Posted by: Federico
Date: June 30, 2005 09:05AM

Hi
I'm trying to make 2 tables and I have to use foreign keys

this is the code I wrote but it doesn't work and I don't uderstand what's wrong with those foreign keys

the given error is:

Error | 1005 | Can't create table '.\cddb\artist.frm' (errno: 150)

this is the code


CREATE TABLE Artist
(artistid INT(10) UNSIGNED AUTO_INCREMENT NOT NULL,
name CHAR (255) NOT NULL,
index (artistid, name),
FOREIGN KEY (artistid, name) REFERENCES CD(artist,name), # ON UPDATE CASCADE,
countryid CHAR (3) NOT NULL,
website CHAR (255),
description TEXT,
PRIMARY KEY (artistid)) ENGINE=INNODB;
show warnings;
INSERT INTO Artist(artistid,name,countryid,website,description) VALUES (NULL, 'The Chemical Brothers', 'UK', 'http://www.thechemicalbrothers.com';, 'blablablablablabla');
INSERT INTO Artist(artistid,name,countryid,website,description) VALUES (NULL, 'Moby', 'USA', 'http://www.moby.com';, 'blabla');
INSERT INTO Artist(artistid,name,countryid,website,description) VALUES (NULL, 'Skin', 'UK', 'http://www.skinmusic.net';, 'blablabla');

show warnings;
CREATE TABLE CD (
cdid int(10) UNSIGNED AUTO_INCREMENT NOT NULL,
artist int(10) UNSIGNED NOT NULL,
name CHAR (255) NOT NULL,
index (artist,name),
FOREIGN KEY (artist, name) REFERENCES Artist(artistid, name),
title char(255) NOT NULL,
label char(255) NOT NULL,
released date NOT NULL,
PRIMARY KEY (cdid)) ENGINE=INNODB;

INSERT INTO CD (artist,name,title,label,released) VALUES (NULL, 'The Chemical Brothers', 'Push the button', 'EMI', '2005-01-24');

thanks a lot for your attenction

Options: ReplyQuote


Subject
Written By
Posted
foreign key usage....what's wrong?
June 30, 2005 09:05AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.