تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
3 الردود
13251 أدوات العرض

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

الصورة الرمزية
إهمال
أفضل إجابة

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.

الصورة الرمزية
إهمال

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

أفضل إجابة

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

الصورة الرمزية
إهمال
أفضل إجابة

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.


الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
0
مايو 21
1645
2
أغسطس 25
2243
1
يوليو 25
778
1
أغسطس 25
1150
0
مايو 25
1267