假设我有以下型号:
class Cart(models.Model):
uuid = models.CharField()
class Order(models.Model):
cart = models.OneToOneField('Cart')
当我想要克隆购物车时:
cart.id = None
cart.order = None
cart.save()
我收到此错误:
ValueError: Cannot assign None: "Cart.order" does not allow null values.
答案 0 :(得分:3)
试试这个:
class Cart(models.Model):
uuid = models.CharField()
class Order(models.Model):
cart = models.OneToOneField('Cart',blank=True,null=True)