我有兩個表朵蒙特和郵遞區號:Django的IntegrityError NOT NULL約束失敗
class Pincode(models.Model):
pincode = models.CharField("PinCode", max_length=6, null=False)
geom = GeopositionField("Location")
class Topmost(models.Model):
pincode = models.ForeignKey(Pincode, unique=True)
rating_pincode = models.CharField("Total Rating points", max_length=255, null=True, blank=True)
frequency = models.CharField("Number of user", max_length=255, null=True, blank=True)
normalized_rank = models.FloatField(null=True, blank=True)
現在我想創建一個自動錄入創建新pincodes時,最頂層。 所以在views.py:
id_past_entries = Topmost.objects.all().values_list('pincode_id', flat=True)
new_entries = Pincode.objects.exclude(id__in=id_past_entries).values_list('id', flat=True)
for new_id in new_entries:
new = Pincode.objects.get(id = new_id)
Topmost.objects.create(pincode=new,rating_pincode=0, frequency=0, normalized_rank=0)
Topmost().save()
但它給錯誤
IntegrityError: NOT NULL constraint failed: display_topmost.pincode_id
任何想法?
你試圖刪除此行? –
是的,我試了一下。 –