简体   繁体   中英

Foreign key issue MySQL

I am having an issue with inputting data from a csv file into a mysql database using JDBC. I have already inserted a table called 'Poet' with the 'PoetName' being the priamry key.

I have populated that table with records that i have held in a CSV file, I then created another table called 'Poem' and it contains a foreign key which is 'PoetName' which references the poet table however whenever I try to populate the table with the CSV file for poems that contains matching values I am being displayed with the following error-

"Cannot add or update a child row: a foreign key constraint fails"

This is strange because the values I have for the primary key 'PoetName' are the same for the values I have used for the foreign key.

Does anyone have an idea of what the issue may be?

Thanks

If you're running into this error, one quick workaround is to add this line to your script:

SET FOREIGN_KEY_CHECKS = 0;

Another note is generally you want your primary key to be of type INT.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM