这是我的型号代码
class Poll(models.Model):
created_at = models.DateTimeField(auto_now=True)
edited_at = models.DateTimeField(auto_now_add=True)
title = models.CharField(max_length=200,default="X vs Y")
description = models.CharField(max_length=200,default="A poll")
def __str__(self):
return self.title
class Item(models.Model):
poll = models.ForeignKey('Poll',on_delete=models.CASCADE)
created_at = models.DateTimeField(auto_now=True)
edited_at = models.DateTimeField(auto_now_add=True)
name = models.CharField(max_length=200)
type_of = models.CharField(max_length=200)
description = models.TextField(max_length=1200)
votes = models.IntegerField(default=0)
def __str__(self):
return self.name
您可以在项目模型中看到投票权。那是个问题。我使用makemigrations
migrate
命令。但我仍然没有得到这样的列错误。
编辑:
这是makemigrations vs_chart
输出
Migrations for 'vs_chart':
vs_chart\migrations\0001_initial.py:
- Create model Item
- Create model Poll
- Add field poll to item
这是migrate
命令输出。
Operations to perform:
Apply all migrations: vs_chart
Running migrations:
No migrations to apply.
答案 0 :(得分:0)
在向项目添加字段轮询之前,您可能会尝试为ForeignKey提供默认值,缺少默认值可能会导致此问题:
poll = models.ForeignKey('Poll',on_delete=models.CASCADE, default=0)