New parent constraint is violated on document directories

Bug #1025896 reported by Don Kirkby
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenUpgrade Addons

Bug Description

When I try to upgrade from 5.0.16 to 6.0, I get the following error (slightly edited):

[...] ERROR:db.cursor:bad query: ALTER TABLE "document_directory" ADD CONSTRAINT "document_directory_dir_parented" check(parent_id IS NOT NULL OR storage_id IS NOT NULL)
Traceback (most recent call last):
  File "[...]/server/upgrade-6.0/bin/", line 131, in execute
    res = self._obj.execute(query, params)
IntegrityError: check constraint "document_directory_dir_parented" is violated by some row

[...] WARNING:orm.schema:Table 'document_directory': unable to add 'check(parent_id IS NOT NULL OR storage_id IS NOT NULL)' constraint !
 If you want to have it, you should update the records and execute manually:
ALTER TABLE "document_directory" ADD CONSTRAINT "document_directory_dir_parented" check(parent_id IS NOT NULL OR storage_id IS NOT NULL)

Steps to reproduce:
1. Create a new database in 5.0 with no sample data and the manufacturing industry profile.
2. Set the view mode to Extended Interface.
3. Leave the default values for all the other setup steps, and set the chart of accounts to "None".
4. From the Administration menu, choose Modules Management: Modules.
5. Open the document module and install it. Accept the default settings.
6. Run the migration using the options, "--update all --stop-after-init". The error occurs as listed above.

The full command line I use for the migration is as follows:
python --database migrationtest --update all --stop-after-init --addons ~/upgrade-addons-6.0 --config ~/openerp-server.config

The constraint depends on values being in the new storage_id field, but it has a default value of null.

Suggested fix:
In the pre-migration, add the storage_id field without the foreign key, and set all records that need a value to use some bogus value. In the post-migration, update the bogus value to point at a valid storage record, and add the foreign key. I'll add a merge proposal.

Related branches

Don Kirkby (donkirkby)
summary: - New document directories reference old ones that have been deleted
+ New parent constraint is violated on document directories
Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Hi Don,

such warnings occur often. We consider it the responsability of the database administrator to audit the logs and update the missing required fields manually for now. When this is done, you can put the constraint in place with another module upgrade.

To support the database administrator in this task, we envision an OpenUpgrade service module that reports on these missing fields but work on it has not yet started.


Changed in openupgrade-addons:
status: New → Confirmed
importance: Undecided → Wishlist
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers