Problem with query Cannot add or update a child row: a foreign key constraint fails (news.video, CONSTRAINT video_ibfk_1 FOREIGN KEY (sid) REFERENCES video (vid) ON DELETE CASCADE ON UPDATE CASCADE)
i have checked other topic on this issue here but my issue did not got solved.
please let me know what should i do to solve this issue
what should we do with a screenshot, how do we convert this into a working example, do you expect us to copy this by hand? You even missed to show half of the tables involved. And this problem relies on the data you are putting into the query, so at least you have to show the queries and some test data
provide an example with schema and test data.
Just use this tool to provide a comprehensable example with all of the necessary data:
You are only showing the details of one of the tables. Need to see both.
If the parent table and the child table have the same column type for the columns you are keying then it is a data problem.
Also, pictures are for hanging on the wall. Post the SQL Schema.
Unexpected beginning of statement. (near “vid” at position 0)
Unexpected beginning of statement. (near “sid” at position 7)
Unexpected beginning of statement. (near “title” at position 14)
Unexpected beginning of statement. (near “titleimage” at position 23)
Unexpected beginning of statement. (near “description” at position 37)
Unexpected beginning of statement. (near “link” at position 52)
Unexpected beginning of statement. (near “datetime” at position 60)
SQL query:
vid, sid, title, titleimage, description, link, datetimeSELECT * FROM video WHERE 1
MySQL said:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'vid, sid, title, titleimage, description, link, datetimeSELECT * F' at line 1
Why don’t you stick to the topic and post random error messages unrelated to the main problem? It’s pretty clear you can’t start a query with a list of columns, a simple select statement is the most basic usage of SQL you should know. And you are still hiding the insert/update query you are actually sending to the database which causes the constraint error.
2/ in the window where you normally run a query, type this –
SHOW CREATE TABLE table1
where table1 is the name of your first table
copy the result (all of it, not the first few characters) and paste it here
3/ repeat for second table
this will show us the relationship (if any) between the tables, which is what we’re trying to help you with regarding the foreign key error you first mentioned way back in post #1