gpt4 book ai didi

python - 当尝试使用 django 模型访问 mysql View 时,它会抛出错误

转载 作者:行者123 更新时间:2023-11-29 15:43:13 27 4
gpt4 key购买 nike

我想使用 django 过滤器访问 mysql View 中的记录,但它抛出错误

class PartnerPayBillSummaryDetails(models.Model):
invoice_no = models.CharField(max_length=200)
invoice_id = models.IntegerField()
partner_id = models.IntegerField()
partner_name = models.CharField(max_length=100)
status = models.CharField(null=False, max_length=50)
invoice_date = models.DateField()
bill_received_date = models.DateField()
due_date = models.DateField()
due_date_ageing = models.IntegerField()
payable_amount = models.DecimalField(max_digits=20, decimal_places=2, default=0)

class Meta:
managed = False
db_table = '66_1_partner_pay_bill_ageing_dtl'
try:
p = PartnerPayBillSummaryDetails.objects.all()
print(p)
except Exception as e:
print(e)

错误:

OperationalError: (1054, "Unknown column '66_1_partner_pay_bill_ageing_dtl.id' in 'field list'")

最佳答案

我找到了答案

it requires a filed as a primary key. I solve this by adding "primary_key=True" in invoice_id

invoice_id = models.IntegerField(primary_key=True)

关于python - 当尝试使用 django 模型访问 mysql View 时,它会抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57357191/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com