【发布时间】:2022-01-23 12:51:07
【问题描述】:
当我尝试将价格添加到 django oscar 时出现此错误,并且此字段在模型中不可编辑或不可写入
我需要帮助才能完成这项工作 IntegrityError at order/order/add/null value in column "total_incl_tax" 违反非空约束细节:失败行包含
class AbstractOrder(models.Model):
"""
The main order model
"""
number = models.CharField(
_("Order number"), max_length=128, db_index=True, unique=True)
# We track the site that each order is placed within
site = models.ForeignKey(
'sites.Site', verbose_name=_("Site"), null=True,
on_delete=models.SET_NULL)
basket = models.ForeignKey(
'basket.Basket', verbose_name=_("Basket"),
null=True, blank=True, on_delete=models.SET_NULL)
# Orders can be placed without the user authenticating so we don't always
# have a customer ID.
user = models.ForeignKey(
AUTH_USER_MODEL, related_name='orders', null=True, blank=True,
verbose_name=_("User"), on_delete=models.SET_NULL)
# Billing address is not always required (eg paying by gift card)
billing_address = models.ForeignKey(
'order.BillingAddress', null=True, blank=True,
verbose_name=_("Billing Address"),
on_delete=models.SET_NULL)
# Total price looks like it could be calculated by adding up the
# prices of the associated lines, but in some circumstances extra
# order-level charges are added and so we need to store it separately
currency = models.CharField(
_("Currency"), max_length=12, default=get_default_currency)
total_incl_tax = models.DecimalField(
_("Order total (inc. tax)"), decimal_places=2, max_digits=12)
total_excl_tax = models.DecimalField(
_("Order total (excl. tax)"), decimal_places=2, max_digits=12)
# Shipping charges
shipping_incl_tax = models.DecimalField(
_("Shipping charge (inc. tax)"), decimal_places=2, max_digits=12,
default=0)
shipping_excl_tax = models.DecimalField(
_("Shipping charge (excl. tax)"), decimal_places=2, max_digits=12,
default=0)
# Not all lines are actually shipped (such as downloads), hence shipping
# address is not mandatory.
shipping_address = models.ForeignKey(
'order.ShippingAddress', null=True, blank=True,
verbose_name=_("Shipping Address"),
on_delete=models.SET_NULL)
shipping_method = models.CharField(
_("Shipping method"), max_length=128, blank=True)
# Identifies shipping code
shipping_code = models.CharField(blank=True, max_length=128, default="")
# Use this field to indicate that an order is on hold / awaiting payment
status = models.CharField(_("Status"), max_length=100, blank=True)
guest_email = models.EmailField(_("Guest email address"), blank=True)
【问题讨论】:
标签: django django-oscar