2017-09-09 5 views
0

Kann jemand das Problem mit meiner create-Anweisung für Tabelle Kontaktgruppe sehen. Ich bekomme immer Fehlercode 1215 kann keine Fremdschlüsseleinschränkung erstellen.MySQL Fremdschlüssel Einschränkung Fehlercode 1215

create table contact( 
ContactID int(5) not null auto_increment, 
ContactName varchar(255) Not null, 
ContactNumber int(5), 
ContactEmail varchar(255), 
primary key(ContactID))ENGINE=InnoDB DEFAULT CHARSET=utf8; 

create table contactgroup(
ContactGroupID int(5) Not Null, 
ContactID int(5) Not Null, 
primary key(ContactGroupID), 
key fk_contactgroup_ContactID (ContactID), 
constraint fk_contactgroup_ContactID 
foreign key(ContactID) 
references contact) ENGINE=InnoDB DEFAULT CHARSET=utf8; 
+0

Mögliche Duplikat [MySQL Fehler 1215 : Kann keine Fremdschlüsseleinschränkung hinzufügen] (https://stackoverflow.com/questions/16969060/mysql-error-1215-cannot-add-foreign-key-constraint) – philipxy

+0

Dies ist eine FAQ, google deinen Titel & lies die Antworten. – philipxy

Antwort

0

Sie müssen sowohl die Tabelle und die Primärschlüsselspalte der Tabelle erwähnen, wenn ein Fremdschlüssel zu definieren:

FOREIGN KEY (ContactID) REFERENCES contact(ContactID) 
+0

Warum antwortest du das anstelle von nahem Wählen als ein offensichtliches Duplikat, das ohne Forschungsaufwand als offensichtlich gilt? – philipxy

Verwandte Themen