Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
6463 มุมมอง

Hi,

I am writing a custom module and models.

My model inherits from res.partner and I am getting the following error.

TypeError: Many2many fields newmodule.partner.channel_ids and res.partner.channel_ids use the same table and columns

 

class Partner(models.Model):
_name = 'newmodel.partner'
_inherit = 'res.partner'

id = fields.Many2one('newmodel.cat',
string="Cat")


class Cat(models.Model):
_name = 'newmodel.cat'
_description = ' '

name = fields.Char(string="Name", required=True)
description = fields.Text()
partner_id = fields.One2many('newmodel.partner', 'id', string="Partners")





How can I fix it? 



อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Just add a relation attribute for the channel_ids field in your custom  model  "newmodule.partner" and provide a different string for the same. like below 

channel_ids = fields.Many2many('mail.channel', relation="relation_newmodule_partner_m2m", string='Channels')

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

You might haven't specified the relation table for the many2many fields, that's why you get this error.


Suppose if you define the new many2many field like this:

partner_ids = fields.Many2many('res.partner')


Change it as follows:

partner_ids = fields.Many2many('res.partner', 'relation_m2m_table', 'rel_1', 'rel_2', string='Partners')

For detailed understanding of the working of many2many field, see: https://www.youtube.com/watch?v=i5gMQke4-Pk


Thanks

อวตาร
ละทิ้ง
ผู้เขียน

Hello, thank you.
I tried doing what you said but iit still gives me the same error.

you need to create a new model ot add fields to exising model ?

Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ก.ค. 21
3558
1
พ.ย. 20
3857
0
เม.ย. 24
969
0
ธ.ค. 23
1740
odoo 14 werkzeug.posixemulation error แก้ไขแล้ว
4
ต.ค. 23
14598