Reputation: 15
in mysql database i have tow tabel , between them relationship "foreign key" when i want need update row but : show this missage
#1451 - Cannot delete or update a parent row: a foreign key constraint fails
(paymesomething.advertisers, CONSTRAINT advertisers_ibfk_1 FOREIGN KEY
(advertiser_id) REFERENCES jobs (advertiser_id))
Upvotes: 1
Views: 820
Reputation: 780798
You're trying to update jobs.advertiser_id
, or delete a row in jobs
, but there's at least one row in paymesomething
that has an advertisers
column that references it as a foreign key. The update would invalidate the relationship, so it's not allowed.
You can add ON DELETE CASCADE ON UPDATE CASCADE
to the foreign key declaration in paymesomething
. Then when you change the parent table, it will automatically delete or update the related rows in paymesomething
.
Upvotes: 2