Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

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

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Cleaning Up Model Relationships After Field Removal

Subscribe

Get notified when there's activity on this post

This question has been flagged
fieldsmodelscustomkeyerrormodels.Model
2 Replies
1337 Views
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
Discard
Kavin C
Author

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
Author 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
Discard
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
Discard
Enjoying the discussion? Don't just read, join in!

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

Sign up
Related Posts Replies Views Activity
Odoo 15 Community: Use Inherited Views to show Custom Field from sale.order in account.move.form
fields models custom
Avatar
0
Jul 22
3464
How to update a computed field based on a dependency from another model? Solved
fields models custom dependencies computed
Avatar
Avatar
Avatar
2
Oct 23
14008
How to add custom field into the Sales Order PDF Print? Solved
pdf fields models custom sale.order
Avatar
Avatar
Avatar
3
Mar 21
15660
Cannot add custom fields in models anymore
fields database models custom bug
Avatar
0
Oct 17
5050
View a field from one model in another model Solved
fields models
Avatar
Avatar
1
Nov 25
6138
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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