ARTICLE DETAIL

建站实战干货

来自一线的建站与推广经验沉淀,每一条都经过真实交付验证。

odoo17彻底删除一个model

2026/9/25 0:11:58 拓冰建站 浏览量
odoo17彻底删除一个model

Odoo的ORM非常牛逼, 但是有一个缺点,就是删除一个模型的时候, 系统并不会帮我们从数据库中删除,然后重启odoo的时候就会报keyerror, 为了彻底从数据库中删除一个模型的数据,我整理了如下sql脚本:

-- 查找model_id
select * from ir_model where model='hx.dcs.device.data';
delete from  ir_model_relation where model=147;
delete from ir_model_fields_selection where field_id in (select id from ir_model_fields where  model_id=147 );
delete from ir_model_fields_group_rel where field_id in (select id from ir_model_fields where  model_id=147 );
delete from ir_model_fields where model_id=147;
delete from ir_model_data where model='hx.dcs.device.data';
delete from ir_model_access where model_id=147;delete from ir_model_constraint where model=147;
delete from ir_model where model='hx.dcs.device.data';

重要提醒:删除有风险,谨慎使用!!!