Jump to content

database foreign key error

Go to solution Solved by Alterlai,

Remove the quotes in the foreign key declaration. Like this:

FOREIGN KEY (opdrachtnummer) REFERENCES opdrachten (opdrachtnummer)

 

Hey guys i need to make a database for school but it wont let me use a foreign key and i can't find why not pls help

Im working in phpmyadmin.

Code:

create TABLE opdrachten(
    opdrachtnummer int not null PRIMARY KEY,
    werkindustrie varchar(200) not null,
    datum date not null,
    kabelleverancier varchar(30) not null,
    overigewaarnemingen varchar(200) not null,
    handtekening varchar(20) not null,
    aantalbedrijfsuern int not null,
    redenenenVoorAfleggen text not null
);
CREATE TABLE checklisten(
    opdrachtnummer int not null,
    kabelid INT  PRIMARY KEY AUTO_INCREMENT not null,
    Zichtbarekabelbreuk6d varchar(50) not null,
    Zichtbarekabelbreuk30d varchar(50) not null,
    afslijpingvandraden text not null,
    roestcorrosie text not null,
    verminderdediameter text not null,
    positiemeetpunt varchar(200) not null,
    beoordeling varchar(200) not null,
    beschadigingenroestvormtpye varchar(200) not null,
    
    FOREIGN KEY ('opdrachtnummer') REFERENCES opdrachten ('opdrachtnummer')
    ON DELETE CASCADE
    ON UPDATE RESTRICT
);

 

Error:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''opdrachtnummer') REFERENCES 'opdrachten' ('opdrachtnummer')
)' at line 13

Link to comment
https://linustechtips.com/topic/803530-database-foreign-key-error/
Share on other sites

Link to post
Share on other sites

Remove the quotes in the foreign key declaration. Like this:

FOREIGN KEY (opdrachtnummer) REFERENCES opdrachten (opdrachtnummer)

 

CPU:

Intel Core i5 2500k - Motherboard: Asus maximus iv gene-z - RAM: 2x Corsair Vengeance Blue 4GB DDR3-1600 CL9 - GPU: ASUS GTX 770 DirectCU II
Case: Coolermaster Centurion 5 II - Storage: Crucial M4 128GB, Seagate barracuda 3TB PSU: XFX 650W XXX Edition Modular PSU - Keyboard: Ducky Shine 2 Pro
Mouse: Razer Deathadder 2013 - Sound: Razer Characias
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×