Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
Hi I have a Add-on with a lot of Fields, I decided to delete a field.
I removed a the field but the field is still in the database.
I searched google an they I only found that i have to uninstall the Add-on and reinstall it again, but then i loos all my data.
And I do not want to delete the field manually in the database, because there are several tausend entries.
Any idea ? or a way that not existing field will be deleted?
I wrote the Script which cleaned the field:
If anyone have the same problem here a small example.
Check first in you database if you have the right field before deleting the field.
select * from ir_model_fields where model ='<Your Mode Name>' and name='<Your Field Name>';
Create a init xml which I put in the data folder.
<function model="clean.field" name="init_remove_field_api7"/>
ADD a python file. (Do not forget to put it in your __init__.py file)
# -*- coding: utf8 -*-
from openerp import api
from openerp.models import TransientModel
_name = "clean.field"
# ToDo can be removed after field is deleted
def init_remove_field_api7(self, cr, uid, ids=None, context=None):
"""Entry function remove Field (called with API7)."""
return self._remove_field(cr, uid, context=context)
"""Removes the Field from the database."""
self.env.cr.execute("""SELECT 1 FROM ir_model_fields
WHERE model = '<Your_Mode_Name>'AND name='<Your_Field_Name>';""")
fields = self.env.cr.fetchall()
self.env.cr.execute("""DELETE FROM ir_model_fields
WHERE model = '<Your_Mode_Name>'
ALTER TABLE <The_Table_Name> DROP COLUMN <Your_Field_Name>;""")
If you delete the database field with pgAdmin3 or directly from a console it should disappears with all his entries. Last time I've tried it worked fine if it is just in one table, don't do it if is a field related to another table. Then you need to delete the field you dropped from the python file too.
In that way even if you rebuild your module the field will not shows again. It's a dirty hack, do a backup before doing it and pay attention with view definitions: if the field you deleted is till declared in a view Odoo will rise an error and could stop the server.
About This Community
This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 8/10/15, 9:43 AM|
|Seen: 4266 times|
|Last updated: 9/21/17, 7:24 AM|