Can't create table (errno: 150) while trying to create a new table [closed]

StackOverflow https://stackoverflow.com/questions/19863934

  •  29-07-2022
  •  | 
  •  

سؤال

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)
);

SQLFiddle demo

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top