有没有一种方法可以阻止Django自动将“ _id”添加到外键

问题描述

有人知道是否有可能阻止Django将“ _id”添加到外键吗?例如:我有一个餐桌服务和背诵。服务具有我命名为re_id的背诵ID(背诵的主键)作为外键。我收到经典错误

(1054,"UnkNown column 'services.re_id_id' in 'field list'")

其中第二个/最后一个“ _id”是自动添加的,我想停止它。我也知道防止错误的一种方法是避免使用“ _id”,但是我想知道是否有一种方法可以使用它。谢谢!

编辑

这是我在models.py中的两个表(服务是behandlung,rechnung是背诵)

class Behandlung(models.Model):
    id = models.AutoField(primary_key=True,unique=True)
    datum = models.DateField()
    behandlung_hn_nr = models.CharField(max_length=30)
    ext4MyHealthIDDoc = models.ForeignKey('Doctors',models.DO_nothing,to_field='ext4MyHealthIDDoc',null=True)
    istpreis = models.FloatField()
    leistungs_text = models.CharField(max_length=75)
    ext4MyHealthIDService = models.ForeignKey('Leistung',to_field='ext4MyHealthIDService',null=True)
    re_id = models.ForeignKey('Rechnung',null=True,unique=False,blank=True)
    bezahlt_am = models.DateField(null=True)
    storniert = models.BooleanField(null=True,default=0)

    def __str__(self):
        return self.leistungs_text

    class Meta:
        managed = True
        db_table = 'behandlung'

class Rechnung(models.Model):
    re_id =models.AutoField(primary_key=True)
    doctor = models.ForeignKey('Doctors',to_field='ext4MyHealthIDDoc')
    erstellt_am = models.DateField()
    rechnungsnummer = models.CharField(max_length=50,null=True)

    class Meta:
        managed=True
        db_table='rechnung'

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)