Ir al contenido
Odoo Menú
  • Iniciar sesión
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • PdV para tiendas
    • PdV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en vivo
    • eLearning
    Cadena de suministro
    • Inventario
    • Manufactura
    • PLM
    • Compras
    • Mantenimiento
    • Calidad
    Recursos humanos
    • Empleados
    • Reclutamiento
    • Vacaciones
    • Evaluaciones
    • Referencias
    • Flotilla
    Marketing
    • Redes sociales
    • Marketing por correo
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyectos
    • Registro de horas
    • Servicio externo
    • Soporte al cliente
    • Planeación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Artículos
    • WhatsApp
    Aplicaciones externas Studio de Odoo Plataforma de Odoo en la nube
  • Industrias
    Venta minorista
    • Librería
    • Tienda de ropa
    • Mueblería
    • Tienda de abarrotes
    • Ferretería
    • Juguetería
    Alimentos y hospitalidad
    • Bar y pub
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidora de bebidas
    • Hotel
    Bienes inmuebles
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión de bienes inmuebles
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Firma contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Manufactura
    • Textil
    • Metal
    • Muebles
    • Comida
    • Cervecería
    • Regalos corporativos
    Salud y ejercicio
    • Club deportivo
    • Óptica
    • Gimnasio
    • Especialistas en bienestar
    • Farmacia
    • Peluquería
    Trades
    • Personal de mantenimiento
    • Hardware y soporte de TI
    • Sistemas de energía solar
    • Zapateros y fabricantes de calzado
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin fines de lucro
    • Agencia para la protección del medio ambiente
    • Alquiler de anuncios publicitarios
    • Fotografía
    • Alquiler de bicicletas
    • Distribuidor de software
    Descubre todas las industrias
  • Odoo Community
    Aprende
    • Tutoriales
    • Documentación
    • Certificaciones
    • Capacitación
    • Blog
    • Podcast
    Fortalece la educación
    • Programa educativo
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtén el software
    • Descargar
    • Compara ediciones
    • Versiones
    Colabora
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Conviértete en partner
    • Servicios para partners
    • Registra tu firma contable
    Obtén servicios
    • Encuentra un partner
    • Encuentra un contador
    • Contacta a un consultor
    • Servicios de implementación
    • Referencias de clientes
    • Soporte
    • Actualizaciones
    GitHub YouTube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicita una demostración
  • Precios
  • Ayuda

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

  • CRM
  • e-Commerce
  • Contabilidad
  • Inventario
  • PoS
  • Proyectos
  • MRP
All apps
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Ayuda

Cleaning Up Model Relationships After Field Removal

Suscribirse

Reciba una notificación cuando haya actividad en esta publicación

Se marcó esta pregunta
fieldsmodelscustomkeyerrormodels.Model
2 Respuestas
1327 Vistas
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 Mejor respuesta

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
Mejor respuesta

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
¿Le interesa esta conversación? ¡Participe en ella!

Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.

Registrarse
Publicaciones relacionadas Respuestas Vistas Actividad
Odoo 15 Community: Use Inherited Views to show Custom Field from sale.order in account.move.form
fields models custom
Avatar
0
jul 22
3458
How to update a computed field based on a dependency from another model? Resuelto
fields models custom dependencies computed
Avatar
Avatar
Avatar
2
oct 23
14003
How to add custom field into the Sales Order PDF Print? Resuelto
pdf fields models custom sale.order
Avatar
Avatar
Avatar
3
mar 21
15639
Cannot add custom fields in models anymore
fields database models custom bug
Avatar
0
oct 17
5049
View a field from one model in another model Resuelto
fields models
Avatar
Avatar
1
nov 25
6135
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento en Odoo.sh
  • Soporte
  • Actualizaciones del software
  • Desarrollos personalizados
  • Educación
  • Encuentra un contador
  • Encuentra un partner
  • Conviértete en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contáctanos
  • Empleos
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Legal • Privacidad
  • Seguridad
الْعَرَبيّة 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 es un conjunto de aplicaciones de código abierto que cubren todas las necesidades de tu empresa: CRM, comercio electrónico, contabilidad, inventario, punto de venta, gestión de proyectos, etc.

La propuesta única de valor de Odoo es ser muy fácil de usar y estar totalmente integrado.

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