V
V
Vladimir Golub2015-05-18 09:11:27
MySQL
Vladimir Golub, 2015-05-18 09:11:27

How to update a foreign key with an UPDATE query?

There are orders tables in it, there is a foreign key of the statuses table (id_status).
You need to change id_status.
I make a request

UPDATE orders_print SET id_status = '2' WHERE id_order_print = '1'

I put down the actions for both deletions and updates.
Gives an error message.
#1452 - Cannot add or update a child row: a foreign key constraint fails (`odeon`.`orders_print`, CONSTRAINT `fk_orders_print_status1` FOREIGN KEY (`id_status`) REFERENCES `status` (`id_status`) ON DELETE CASCADE ON UPDATE CASCADE)
How to fix?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2015-05-18
@RazerVG

Most likely there is no status in the `status` table with `id_status` = 2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question