You need to define to which column your foreign key relates, not only the table
CREATE TABLE PianoDS
(
sid CHAR(20),
cid CHAR(20),
grade CHAR(20),
PRIMARY KEY (sid,cid),
FOREIGN KEY (sid) REFERENCES Studenti(id)
);
سؤال
On PHPMyAdmin, I entered into the database I am using, then selected SQL tab, and entered:
CREATE TABLE PianoDS
(sid CHAR(20),
cid CHAR(20),
grade CHAR(20),
PRIMARY KEY (sid,cid),
FOREIGN KEY (sid) REFERENCES Studenti);
but I obtain
1005 - Can't create table 'basi_di_dati.PianoDS' (errno: 150) (Dettagli...)
المحلول
You need to define to which column your foreign key relates, not only the table
CREATE TABLE PianoDS
(
sid CHAR(20),
cid CHAR(20),
grade CHAR(20),
PRIMARY KEY (sid,cid),
FOREIGN KEY (sid) REFERENCES Studenti(id)
);