Foreign key constraint fail issue

I got this error while trying to import .sql file in PhpMyadmin.



Now when i try to delete anything related from my website portal i get this error.

My .sql database :
https://pastebin.com/NjXKf3YY

Help me fix this issue thank you

ON DELETE RESTRICT is the default

gotta delete the studentquestion before you can delete the question

1 Like

Sorry can you be more specific? i didn’t get you exactly. :sweat:

What should i do to avoid “Sql query” error while importing .sql file into phpmyadmin?

the error did not occur when you imported the .sql file

the error did not occur when you executed the .sql file

the error occurred when you tried to delete a question, while it still had a related studentquestion child row

Yes sql query error occured while importing.(Database imported successfully with this error shown in phpmyadmin)


i’m sorry, i was looking at this part of your original post –

okay, here’s your problem…

the sql script loads some rows into only two tables – adminlogin and studentquestion

then it attempts to define the FK from studentquestion to question

this fails because there are no rows in the question table that correspond to the rows in studentquestion

solution? don’t load any data until all the keys are defined

1 Like

tq. I’ll try your suggestion. :slight_smile:

This fixed my issue tq.

And this helped me fix “why i can’t delete questions”.

Thank you. :slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.