使用get_or_create的FOREIGN KEY约束失败

时间:2018-08-17 15:27:33

标签: python django sqlite

跟踪:

http://dpaste.com/126CW8T

触发错误的视图是这样的:

class Order(models.Model):
    fecha_reparto = models.ForeignKey(DiasDeReparto, on_delete=models.CASCADE, default= 1)
    order_nodo = models.ForeignKey(Nodo, on_delete=models.CASCADE, default= 1)
    ref_code = models.CharField(max_length=15)
    owner = models.ForeignKey(UserProfile, on_delete=models.CASCADE)
    is_ordered = models.BooleanField(default=False)
    date_ordered = models.DateTimeField(null=True)

型号:

SELECT a.*, (case when exists (select 1
                               from b inner join 
                                    c
                                    on b.value = c.value
                               where b.customer = a.customer and 
                                     c.item = a.item
                              ) 
                  then 1 else 0
             end) as valuematch
FROM a;

0 个答案:

没有答案