This question has been flagged
3 Replies
9803 Views

Hi:

I see this is a long standing bug, I deleted some models in the code but now upgrading the module raise this error:

  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_model.py", line 1202, in unlink
    not self.env[selection.field_id.model]._abstract:
  File "/usr/lib/python3/dist-packages/odoo/api.py", line 463, in __getitem__
    return self.registry[model_name]._browse(self, (), ())
  File "/usr/lib/python3/dist-packages/odoo/modules/registry.py", line 177, in __getitem__
    return self.models[model_name]
KeyError: 'my.deleted.model'

Any solutions for this bug, besides brute force suggested in this post \https://github.com/odoo/odoo/issues/27758 ?

DELETE FROM ir_model_fields WHERE model = '<model>';
DELETE FROM ir_model_constraint WHERE model = (SELECT id FROM ir_model WHERE model = '<model>');
DELETE FROM ir_model_relation WHERE model = (SELECT id FROM ir_model WHERE model = '<model>');
DELETE FROM ir_model WHERE model = '<model>';


Thanks!

Mayte

Avatar
Discard
Best Answer

Thanks for the answer inside the question that helped me to solved my problem.

If some one is looking for the force solution, you can try this:

sudo -i -u postgres
psql -d `your-db-name`
DELETE FROM ir_model_fields WHERE model = '`model`'; DELETE FROM ir_model_constraint WHERE model = (SELECT id FROM ir_model WHERE model = '`model`'); DELETE FROM ir_model_relation WHERE model = (SELECT id FROM ir_model WHERE model = '`model`'); DELETE FROM ir_model WHERE model = '`model`';

Remember to replace `your-db-name` and `model` with your actual values.

Thanks.

Avatar
Discard

This worked for me. What can be done to avoid having to do this?

Best Answer

Go trough your database and delete the related model that KeyError.


user$host: sudo su - postgres
postgress$host: psql
postgres=#  \connect "database_name";
connected_db=# DELETE FROM ir_model WHERE model='model.name.that.keyError';

Thanks,
Tri

Avatar
Discard
Best Answer

EDIT:

For all experiencing this issue, try deleting model's record in your security CSV. That is file in your security folder where you define default access to your models.


Avatar
Discard