4đź‘Ť
âś…
This problem is by a “mutating table”, when DJANGO emulate the ON_CASCADE, first delete the row on table “ProductPricing” and the insert on “OldProductPricing” is over a row in “Product” which will disappear. You have other options:
- Delete the trigger and manage the logic in the Product.save() and ProductPricing.save(), and change on_delete=CASCADE by on_delete=DO_NOTHING.
or
- A log table (“OldProductPricing”) should keep the data for ever, and show all the changes in the history from “Product”, thus you should delete the foreign key from “OldProductPricing” to “Product.
Source:stackexchange.com