简体   繁体   English

django orm 中的现场冲突

[英]Field clashes in django orm

I have some problems with Django ORM.我对 Django ORM 有一些问题。 I have three classes:我有三个班级:

transaction.py交易.py

class Transaction(models.Model):

    class Status(models.TextChoices):
        PENDING = 'Pending'
        PROCESSING = 'Processing'
        CHARGED = 'Charged'
        AUTHORIZED = 'Authorized'
        CANCELLED = 'Cancelled'
        REJECTED = 'Rejected'
        ERROR = 'Error'
        ISSUED = 'Issued'

    amount = models.DecimalField(max_digits=6, decimal_places=2)  # in USD
    status = models.CharField(
        max_length=15,
        choices=Status.choices,
        default=Status.PROCESSING,
    )
    created_at = models.DateTimeField()
    updated_at = models.DateTimeField()
    from_account = models.CharField(max_length=16)
    to_account = models.CharField(max_length=16)

payments.py付款.py

class Payment(Transaction):
    order = models.ForeignKey(Order, on_delete=models.CASCADE)

    def __str__(self):
        return f"Payment {super().__str__()}"


class Refund(Payment):
    payment = models.ForeignKey(
        Payment,
        on_delete=models.CASCADE,
        related_name='parent_payment'
    )

    def __str__(self):
        return f"Refund payment={self.payment.id} {super(Transaction, self).__str__()}"

And when I trying to do migration I have this error当我尝试进行迁移时,我遇到了这个错误

SystemCheckError: System check identified some issues:

ERRORS:
booking.Refund.payment: (models.E006) The field 'payment' clashes with the field 'payment' from model 'booking.transaction'.

As I understand the problem related to inheritance and its specific in ORM, but I'm not sure据我了解与 inheritance 相关的问题及其在 ORM 中的具体问题,但我不确定

just add it只需添加它


class Meta:
abstract = True

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM