Upgrade 7.2->7.4 "ir_ui_view_tree_optional" violates foreign key constraint "ir_ui_view_tree_optional_field_model_name_model_fkey"

I am not sure if this is a bug or if it is a problem with my database.
Database update on 7.2 works.
Database validation does not produce anything relevant on 7.2.
Update from 7.2 → 7.4 produces:
DETAIL: Key (field, model)=(move_description, account.general_ledger.line) is not present in table "ir_model_field".

While I do have some custom modules, to me it does not seem like they are causing the issue.
I have tested creating a new database with 7.2 and updating it to 7.4 and that works with no problems.

dot$ . 72/bin/activate
(72) dot$ trytond-admin -c trytond.conf -d test --all 
(72) dot$ . 74/bin/activate 
(74) dot$ trytond-admin -c trytond.conf -d test --all 
/var/trytond/74/lib/python3.11/site-packages/urllib3/__init__.py:35: NotOpenSSLWarning: urllib3 v2 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'LibreSSL 3.9.0'. See: https://github.com/urllib3/urllib3/issues/3020
  warnings.warn(
Traceback (most recent call last):
  File "/var/trytond/74/bin/trytond-admin", line 33, in <module>
    admin.run(options)
  File "/var/trytond/74/lib/python3.11/site-packages/trytond/admin.py", line 59, in run
    pool.init(update=options.update, lang=list(lang),
  File "/var/trytond/74/lib/python3.11/site-packages/trytond/pool.py", line 144, in init
    restart = not load_modules(
                  ^^^^^^^^^^^^^
  File "/var/trytond/74/lib/python3.11/site-packages/trytond/modules/__init__.py", line 402, in load_modules
    _load_modules(update)
  File "/var/trytond/74/lib/python3.11/site-packages/trytond/modules/__init__.py", line 372, in _load_modules
    load_module_graph(graph, pool, update, lang, indexes)
  File "/var/trytond/74/lib/python3.11/site-packages/trytond/modules/__init__.py", line 200, in load_module_graph
    cls.__register__(module)
  File "/var/trytond/74/lib/python3.11/site-packages/trytond/ir/ui/view.py", line 584, in __register__
    cursor.execute(*table.update(
  File "/var/trytond/74/lib/python3.11/site-packages/trytond/backend/postgresql/database.py", line 76, in execute
    cursor.execute(self, sql, args)
psycopg2.errors.ForeignKeyViolation: insert or update on table "ir_ui_view_tree_optional" violates foreign key constraint "ir_ui_view_tree_optional_field_model_name_model_fkey"
DETAIL:  Key (field, model)=(move_description, account.general_ledger.line) is not present in table "ir_model_field".

More detail

trytond-admin -c trytond.conf -d test -vv --all
...
84549 10540007131344 [2024-11-06 12:09:45,949] INFO trytond.modules ir register ir.ui.view.show.start
84549 10540007131344 [2024-11-06 12:09:45,951] INFO trytond.modules ir register ir.ui.view_tree_width
84549 10540007131344 [2024-11-06 12:09:45,964] INFO trytond.modules ir register ir.ui.view_tree_optional
84549 10540007131344 [2024-11-06 12:09:45,978] WARNING trytond.backend.postgresql.table Unable to set not null on column model of table ir_ui_view_tree_optional.
Try restarting one more time.
If that doesn't work update the records and restart again.
Traceback (most recent call last):
  File "/var/trytond/74/bin/trytond-admin", line 33, in <module>
    admin.run(options)
  File "/var/trytond/74/lib/python3.11/site-packages/trytond/admin.py", line 59, in run
    pool.init(update=options.update, lang=list(lang),
  File "/var/trytond/74/lib/python3.11/site-packages/trytond/pool.py", line 144, in init
    restart = not load_modules(
                  ^^^^^^^^^^^^^
  File "/var/trytond/74/lib/python3.11/site-packages/trytond/modules/__init__.py", line 402, in load_modules
    _load_modules(update)
  File "/var/trytond/74/lib/python3.11/site-packages/trytond/modules/__init__.py", line 372, in _load_modules
    load_module_graph(graph, pool, update, lang, indexes)
  File "/var/trytond/74/lib/python3.11/site-packages/trytond/modules/__init__.py", line 200, in load_module_graph
    cls.__register__(module)
  File "/var/trytond/74/lib/python3.11/site-packages/trytond/ir/ui/view.py", line 584, in __register__
    cursor.execute(*table.update(
  File "/var/trytond/74/lib/python3.11/site-packages/trytond/backend/postgresql/database.py", line 76, in execute
    cursor.execute(self, sql, args)
psycopg2.errors.ForeignKeyViolation: insert or update on table "ir_ui_view_tree_optional" violates foreign key constraint "ir_ui_view_tree_optional_field_model_name_model_fkey"
DETAIL:  Key (field, model)=(move_description, account.general_ledger.line) is not present in table "ir_model_field".


Since Use origin description as fallback description for account move and line (73fda56fc994) · Commits · Tryton / Tryton · GitLab the general ledger lines have no more a move_description field.
But it seems that you still have reference to this field in the ir_ui_view_tree_optional. 7.4 series enforces the data integrity to avoid such garbage data.
You need to remove the record (and any other) violating the foreign key.

We may write a migration query for Replace menu entries for view configuration by relate on model (!1727) · Merge requests · Tryton / Tryton · GitLab.

In my case
delete from ir_ui_view_tree_optional where field='move_description';
deleted one record and fixed the issue. Thank you Cedric.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.