Python odoo pb积分误差
我不明白确切的原因,但我有这个错误。客户组id在我的表中 我所有的亲戚都在那里 你有什么想法吗 多谢各位Python odoo pb积分误差,python,database,odoo,integrity,Python,Database,Odoo,Integrity,我不明白确切的原因,但我有这个错误。客户组id在我的表中 我所有的亲戚都在那里 你有什么想法吗 多谢各位 IntegrityError: insert or update on table "products_group" violates foreign key constraint "products_group_customers_group_i_fkey" DETAIL: Key (customers_group_id)=(25) is not present in table "cu
IntegrityError: insert or update on table "products_group" violates foreign key constraint "products_group_customers_group_i_fkey"
DETAIL: Key (customers_group_id)=(25) is not present in table "customers_group".
我的代码
from openerp.osv import fields, osv
from openerp.tools.translate import _
class customers_group(osv.osv):
_name = 'customers.group'
_rec_name = 'customers_group_name'
_columns = {
'customers_group_id': fields.integer('Group Id', size=5, help="Id customer group"),
'customers_group_name': fields.char('Group Name', size=30, required=True),
.....
}
class res_partner(osv.osv):
_inherit = 'res.partner'
_columns = {
'partner_customer_group_id': fields.many2one('customers.group','Customers Group', help='Customers group.')
}
产品组
from openerp.osv import orm, fields
from openerp.tools.translate import _
class products_group(orm.Model):
_name = 'products.group'
_columns = {
'customers_group_id': fields.integer('Customer group Id', size=20, help='id of customers group'),
'products_id': fields.integer('Product Id', size=5, help="Id product must be unique"),
'products_model_group': fields.char('Product model group', size=30, help='Product model'),
.....
}
我根据您的代码修正了类似的情况:
@api.model
def _set_null(self):
if self.customers_group_id == 25:
self.customers_group_id = None
_columns = {
'customers_group_id': fields.integer('Group Id', size=5, help="Id customer group", compute='_set_null'),
.....
}
我重新启动了服务,删除了方法_set _null和compute属性后,因为25的值被替换为null,所以完整性错误应该不再发生。产品组的代码在哪里?。您可能已经从表customer.group中删除了id为25的记录,这就是它抛出外键约束冲突错误的原因。这意味着数据已从主表customer.group中删除,其仍在其他表中的某处引用。检查它。我在上面插入了produts_组,不,每次都是新数据,没有冲突。对不起,你是对的,我创建了一个新的基础,这是可以的。谢谢你的帮助我没弄清楚,你的问题解决了吗?是的,我的问题解决了,tk