OpenUpgrade
OpenUpgrade copied to clipboard
Error migrating 7 to 8 (sale module)
Hello,
I have the following error when i run the migration:
2015-07-07 10:13:18,257 26710 ERROR Erp7_migrated openerp.sql_db: bad query: ALTER TABLE "sale_order_line" ADD FOREIGN KEY ("order_partner_id") REFERENCES "res_partner" ON DELETE set null
Traceback (most recent call last):
File "/var/tmp/openupgrade/8.0/server/openerp/sql_db.py", line 234, in execute
res = self._obj.execute(query, params)
IntegrityError: insert or update on table "sale_order_line" violates foreign key constraint "sale_order_line_order_partner_id_fkey"
DETAIL: Key (order_partner_id)=(353) is not present in table "res_partner".
Does anybody know how to solve this?
Thank you
This is because you have an inconsistent related field (this is due to a bug in ORM). You can fix it this way:
UPDATE sale_order_line sol SET partner_id=so.partner_id FROM sale_order so WHERE so.id = sol.order_id AND sol.partner_id != so.partner_id;
Other thing that you maybe need is to remove orphaned sale order lines:
DELETE sale_order_line WHERE order_id IS NULL;
Thank you very much for the quick answer. There is no 'partner_id' in my sale_order_line. Do you mean 'order_partner_id'?
Thank you
Sorry, that's it. I say the field names from memory
Thank you, that did the trick :)