Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

Cleaning Up Model Relationships After Field Removal

Subscriure's

Get notified when there's activity on this post

This question has been flagged
fieldsmodelscustomkeyerrormodels.Model
2 Respostes
1350 Vistes
Avatar
Kavin C

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.


0
Avatar
Descartar
Kavin C
Autor

The previously implemented code has been removed from the project. I created a new model named x.custom.model, which includes four new fields and a ForeignKey field (x_dummy_fk) referencing the x.base.model table. The x.base.model also includes a One2many field named x_dummy_one2many, pointing to x.custom.model using x_dummy_fk as the inverse_name.

Although the old code has been deleted, I'm still encountering an error related to x_dummy_one2many. I need to ensure that all references to this field are fully removed from both the database and the source code. Please help identify and clean up any remaining dependencies

x_dummy_one2many = fields.One2many(

    "x.custom.model",

    inverse_name="x_dummy_fk",

    string="Dummy Rebate",

)


could you please help me to erase all related code.

Avatar
Kavin C
Autor Best Answer

The previously implemented code has been removed from the project. I created a new model named x.custom.model, which includes four new fields and a ForeignKey field (x_dummy_fk) referencing the x.base.model table. The x.base.model also includes a One2many field named x_dummy_one2many, pointing to x.custom.model using x_dummy_fk as the inverse_name.

Although the old code has been deleted, I'm still encountering an error related to x_dummy_one2many. I need to ensure that all references to this field are fully removed from both the database and the source code. Please help identify and clean up any remaining dependencies


x_dummy_one2many = fields.One2many(

    "x.custom.model",

    inverse_name="x_dummy_fk",

    string="Dummy Rebate",

)


could you please help me to erase all related code.

0
Avatar
Descartar
Avatar
Cybrosys Techno Solutions Pvt.Ltd
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

0
Avatar
Descartar
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrar-se
Related Posts Respostes Vistes Activitat
Odoo 15 Community: Use Inherited Views to show Custom Field from sale.order in account.move.form
fields models custom
Avatar
0
de jul. 22
3474
How to update a computed field based on a dependency from another model? Solved
fields models custom dependencies computed
Avatar
Avatar
Avatar
2
d’oct. 23
14017
How to add custom field into the Sales Order PDF Print? Solved
pdf fields models custom sale.order
Avatar
Avatar
Avatar
3
de març 21
15668
Cannot add custom fields in models anymore
fields database models custom bug
Avatar
0
d’oct. 17
5056
View a field from one model in another model Solved
fields models
Avatar
Avatar
1
de nov. 25
6139
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now