Hi, this is my first thread so if I doing wrong some things please don't hate me :) I'm using Migration to build my database and I have a problem with ONE foreign key! My database contain 5 foreign key but I don't know why only one doesn't work. Full code: http://pastebin.com/4XRD1TuG
The problem is in Users <- Levels (N <- 1) If I try to add a new users laravel returns me this error:
Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (squarenews2
.users
, CONSTRAINT users_level_id_foreign
FOREIGN KEY (level_id
) REFERENCES levels
(id
))
If I try with phpmyadmin the user is placed but foreign key is null....
Where am I wrong?
Thankyou :)
First the good news: we don't hate you! :D
I've had this error a few times and it's annoying. It's either that the FK is not set in the query, or the FK does not exist. Take a look at your code to make sure that everything is set OK.
Mei
meigwilym said:
First the good news: we don't hate you! :D
I've had this error a few times and it's annoying. It's either that the FK is not set in the query, or the FK does not exist. Take a look at your code to make sure that everything is set OK.
Mei
When I try with phpmyadmin, I use che dropdown menu to select the FK... So the FK exists! Migration code is all right? (Ps: if I remove foreign key , the query run without problems!)
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community