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';
重要提醒:删除有风险,谨慎使用!!!