IntegrityError: could not create unique index

Asked by Thomas Winteler (Win-Soft)

Hi

Great software.. but maybe it breaks in a multi company instance...
I backuped 6.0.4 db (pgsql8.4) with GTK 6.0 client and imported it in a 6.1 db (pgsql 9.1) with GTK 6.1 client.. so far so good.
Then i run following, see also output and check all the lines with DETAIL:.... dublicated...

./server/openerp-server -r openerp-testing -w openerp55 --netrpc-port=8070 --xmlrpc-port=8069 --xmlrpcs-port=8071 --db_host=localhost --db_port=5433 --addons-path="/home/thomi/Daten/openerp-dev/openupgrade_6.1/addons" -d winsoft_20121013 -u all --stop-after-init
2012-10-16 11:49:01,653 7496 INFO ? openerp: OpenERP version 6.1
2012-10-16 11:49:01,653 7496 INFO ? openerp: addons paths: /home/thomi/Daten/openerp-dev/openupgrade_6.1/addons
2012-10-16 11:49:01,653 7496 INFO ? openerp: database hostname: localhost
2012-10-16 11:49:01,654 7496 INFO ? openerp: database port: 5433
2012-10-16 11:49:01,654 7496 INFO ? openerp: database user: openerp-testing
2012-10-16 11:49:01,782 7496 INFO ? openerp.addons.web: embedded mode
2012-10-16 11:49:02,191 7496 INFO winsoft_20121013 openerp.modules.loading: module base: loading objects
2012-10-16 11:49:02,193 7496 INFO winsoft_20121013 openerp.modules.migration: module base: Running migration [>6.1.1.3] pre-migration
2012-10-16 11:49:02,193 7496 INFO winsoft_20121013 OpenUpgrade: /home/thomi/Daten/openerp-dev/openupgrade_6.1/base/migrations/6.1.1.3/pre-migration.py called
2012-10-16 11:49:02,195 7496 WARNING winsoft_20121013 OpenUpgrade: No rows affected for query "ALTER TABLE ir_model_fields ADD COLUMN serialization_field_id INTEGER REFERENCES ir_model_fields ON DELETE CASCADE"
2012-10-16 11:49:02,196 7496 INFO winsoft_20121013 OpenUpgrade: table res_users: drop column user_email
2012-10-16 11:49:02,197 7496 WARNING winsoft_20121013 OpenUpgrade: table res_users: column user_email did not exist
2012-10-16 11:49:02,197 7496 INFO winsoft_20121013 OpenUpgrade: table res_users, column email: renaming to user_email
2012-10-16 11:49:02,200 7496 WARNING winsoft_20121013 OpenUpgrade: No rows affected for query "UPDATE ir_module_module SET name = plugin_outlook WHERE name = outlook"
2012-10-16 11:49:02,201 7496 WARNING winsoft_20121013 OpenUpgrade: No rows affected for query "UPDATE ir_model_data SET module = plugin_outlook WHERE module = outlook "
2012-10-16 11:49:02,202 7496 WARNING winsoft_20121013 OpenUpgrade: No rows affected for query "UPDATE ir_module_module SET name = plugin_thunderbird WHERE name = thunderbird"
2012-10-16 11:49:02,254 7496 WARNING winsoft_20121013 OpenUpgrade: No rows affected for query "UPDATE ir_model_data SET module = plugin_thunderbird WHERE module = thunderbird "
2012-10-16 11:49:02,254 7496 WARNING winsoft_20121013 OpenUpgrade: No rows affected for query "UPDATE ir_module_module SET name = mail WHERE name = mail_gateway"
2012-10-16 11:49:02,358 7496 WARNING winsoft_20121013 OpenUpgrade: No rows affected for query "UPDATE ir_model_data SET module = mail WHERE module = mail_gateway "
2012-10-16 11:49:02,469 7496 WARNING winsoft_20121013 OpenUpgrade: No rows affected for query "UPDATE ir_module_module SET demo = false"
2012-10-16 11:49:02,588 7496 INFO winsoft_20121013 openerp.modules.module: module base: creating or updating database tables
2012-10-16 11:49:02,816 7496 ERROR winsoft_20121013 openerp.sql_db: bad query: ALTER TABLE "ir_sequence_type" ADD CONSTRAINT "ir_sequence_type_code_unique" unique(code)
Traceback (most recent call last):
  File "/home/thomi/Daten/openerp-dev/openupgrade_6.1/server/openerp/sql_db.py", line 212, in execute
    res = self._obj.execute(query, params)
IntegrityError: could not create unique index "ir_sequence_type_code_unique"
DETAIL: Key (code)=(g&v_n) is duplicated.

2012-10-16 11:49:02,816 7496 WARNING winsoft_20121013 openerp.osv.orm.schema: Table 'ir_sequence_type': unable to add 'unique(code)' constraint !
 If you want to have it, you should update the records and execute manually:
ALTER TABLE "ir_sequence_type" ADD CONSTRAINT "ir_sequence_type_code_unique" unique(code)
2012-10-16 11:49:07,534 7496 ERROR winsoft_20121013 openerp.sql_db: bad query: ALTER TABLE "res_currency" ADD CONSTRAINT "res_currency_unique_name_company_id" unique (name, company_id)
Traceback (most recent call last):
  File "/home/thomi/Daten/openerp-dev/openupgrade_6.1/server/openerp/sql_db.py", line 212, in execute
    res = self._obj.execute(query, params)
IntegrityError: could not create unique index "res_currency_unique_name_company_id"
DETAIL: Key (name, company_id)=(kr, 1) is duplicated.

2012-10-16 11:49:07,535 7496 WARNING winsoft_20121013 openerp.osv.orm.schema: Table 'res_currency': unable to add 'unique (name, company_id)' constraint !
 If you want to have it, you should update the records and execute manually:
ALTER TABLE "res_currency" ADD CONSTRAINT "res_currency_unique_name_company_id" unique (name, company_id)
2012-10-16 11:49:07,539 7496 ERROR winsoft_20121013 openerp.sql_db: bad query: CREATE UNIQUE INDEX res_currency_unique_name_company_id_idx
                          ON res_currency
                          (name, (COALESCE(company_id,-1)))
Traceback (most recent call last):
  File "/home/thomi/Daten/openerp-dev/openupgrade_6.1/server/openerp/sql_db.py", line 212, in execute
    res = self._obj.execute(query, params)
IntegrityError: could not create unique index "res_currency_unique_name_company_id_idx"
DETAIL: Key (name, (COALESCE(company_id, (-1))))=(kr, 1) is duplicated.

2012-10-16 11:49:07,659 7496 ERROR winsoft_20121013 openerp: Failed to initialize database `winsoft_20121013`.
Traceback (most recent call last):
  File "./server/openerp-server", line 95, in preload_registry
    db, registry = openerp.pooler.get_db_and_pool(dbname, update_module=config['init'] or config['update'], pooljobs=False)
  File "/home/thomi/Daten/openerp-dev/openupgrade_6.1/server/openerp/pooler.py", line 33, in get_db_and_pool
    registry = RegistryManager.get(db_name, force_demo, status, update_module, pooljobs)
  File "/home/thomi/Daten/openerp-dev/openupgrade_6.1/server/openerp/modules/registry.py", line 180, in get
    update_module, pooljobs)
  File "/home/thomi/Daten/openerp-dev/openupgrade_6.1/server/openerp/modules/registry.py", line 202, in new
    openerp.modules.load_modules(registry.db, force_demo, status, update_module)
  File "/home/thomi/Daten/openerp-dev/openupgrade_6.1/server/openerp/modules/loading.py", line 460, in load_modules
    loaded_modules, processed_modules = load_module_graph(cr, graph, status, perform_checks=(not update_module), report=report, registry=registry)
  File "/home/thomi/Daten/openerp-dev/openupgrade_6.1/server/openerp/modules/loading.py", line 322, in load_module_graph
    init_module_models(cr, package.name, models)
  File "/home/thomi/Daten/openerp-dev/openupgrade_6.1/server/openerp/modules/module.py", line 382, in init_module_models
    obj.init(cr)
  File "/home/thomi/Daten/openerp-dev/openupgrade_6.1/server/openerp/addons/base/res/res_currency.py", line 96, in init
    (name, (COALESCE(company_id,-1)))""")
  File "/home/thomi/Daten/openerp-dev/openupgrade_6.1/server/openerp/sql_db.py", line 152, in wrapper
    return f(self, *args, **kwargs)
  File "/home/thomi/Daten/openerp-dev/openupgrade_6.1/server/openerp/sql_db.py", line 212, in execute
    res = self._obj.execute(query, params)
IntegrityError: could not create unique index "res_currency_unique_name_company_id_idx"
DETAIL: Key (name, (COALESCE(company_id, (-1))))=(kr, 1) is duplicated.

Is it real, that i breaks on a multi company instance?

additional information..
I checked out res_currency and we use one currency (CHF) for two companies.. in res_currency the company_id column is empty, so we can use the same currency for both companies.. same happens on a customer of us which has about 6 companies sharing the same currency...

Thanks for feedback...

regards from swiss-german
thomi

Question information

Language:
English Edit question
Status:
Solved
For:
OpenUpgrade Server Edit question
Assignee:
No assignee Edit question
Solved by:
Stefan Rijnhart (Opener)
Solved:
Last query:
Last reply:
Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) said :
#1

Hi Thomas,

this kind of breakage is not something that we can solve in the OpenUpgrade server. Many constraints are added in OpenERP 6.1, and you need to use this feedback to prepare your 6.0 database for the upgrade using these errors.

The error indicates not that sharing a single currency between companies is a problem, but having multiple currencies with the same name (at least one called 'kr') assigned to the same company.

So if you encounter the error 'could not create unique index', you need to go back to your 6.0 database, adapt and try again.

Cheers,
Stefan.

Revision history for this message
Best Stefan Rijnhart (Opener) (stefan-opener) said :
#2

Hi Thomas,

as it happened, I performed a migration myself today giving me the opportunity to reflect on the matter. This currency is an exception. We already cover the general cases I think. Could you test the proposed fix at

lp:~therp-nl/openupgrade-server/6.1-lp1067874-res_currency_init_savepoint

Cheers,
Stefan.

Revision history for this message
Thomas Winteler (Win-Soft) (thomi) said :
#3

Hello Stefan

Great work.. i needed forst remove some dublicates and then run the -u all twice...
Some warnings/errors about third party modules, but can access the db on 6.1 and need now investigate time, which third party module has a 6.1 version.. and what to change in my own modules...

Will come back, if i find any other problem according to OpenUpgrade process..

have a nice day

Cheers
Thomas

Revision history for this message
Thomas Winteler (Win-Soft) (thomi) said :
#4

Thanks Stefan Rijnhart (Therp), that solved my question.