Skip to Content
Menu
This question has been flagged

I removed a field (dummy_field_ids) that was used in a One2many relationship in a model, but Odoo is still referencing it. How can I safely clean up all the relationships and data that depended on this fields.


DetailsExplanation:

I recently removed a custom module from my Odoo installation, which contained several fields and models. After removing the module code, I started encountering errors in the system, specifically KeyError messages referencing a field (dummy_field_ids) that I had deleted from the code.

From what I understand, even though the Python code defining the field no longer exists, Odoo's database still contains metadata and possibly table columns related to this field. This causes the system to continue expecting the field, which breaks views, forms, and certain automated actions.

Here's a summary of the situation:

  • The module has been removed, including all model definitions for dummy_field_ids.
  • The database still contains references to this field in the ir_model_fields table and in the actual table for the model.
  • Attempts to open forms or pages that previously used this field now throw errors.
  • I cannot uninstall the module (it's already removed) and manually deleting database columns seems risky due to foreign keys, constraints, and large amounts of data.

What I want to achieve:

  1. Remove the field completely from Odoo's metadata (ir_model_fields).
  2. Remove the actual column from the database table safely.
  3. Ensure that no views, actions, or reports reference this field anymore to prevent errors.
  4. Do this without uninstalling any modules and without losing other unrelated data.

I've seen some discussions suggesting writing a script to delete the field on server start or using SQL directly, but I want a safe, recommended approach that works with Odoo's ORM and handles both the metadata and database side.

Has anyone dealt with a similar situation? What is the recommended way to clean up removed fields from both the Odoo models and the database? Any scripts, methods, or best practices would be very helpful.


Avatar
Discard
Best Answer

Hi,


Odoo stores field definitions in the database (ir_model_fields) and also physically adds columns to the underlying PostgreSQL table for the model.

If the Python code is gone but the metadata remains, Odoo will still try to load those fields, leading to the KeyError: 'dummy_field_ids' problem you’re seeing.


When you uninstall a module from inside Odoo, it removes:

            - The ir_model_fields records for its fields.

           - The database columns for non-stored computed fields and certain m2m/o2m rel tables.

           - View XML references to those fields.


If you delete the module files without uninstalling, Odoo:

           - Can’t execute the cleanup hooks.

           - Leaves behind database records and sometimes columns that reference the removed fields.

          - This makes the ORM and view loader fail when they try to render a view containing the field.


Methods

1- Remove metadata (Odoo ORM way):\

    self.env['ir.model.fields'].search([('name', '=', 'dummy_field_ids')]).unlink()


2- Remove references in views:

      self.env['ir.ui.view'].search([('arch_db', 'ilike', 'dummy_field_ids')]).unlink()


3-Drop the database column

      - If the field was store=True (most o2m/m2m are), it will have a column or a related table in PostgreSQL.If present, drop it:

                     ALTER TABLE table_name_for_your_model DROP COLUMN dummy_field_ids;

Note:- Be sure no remaining code or module expects this field before dropping.


4- Clear caches & restart


Hope it helps

Avatar
Discard
Related Posts Replies Views Activity
0
Jul 22
2543
2
Oct 23
12887
3
Mar 21
14708
0
Oct 17
4185
1
Jun 25
5131