![](/img/trans.png)
[英]'question_text' is an invalid keyword argument for this function
[英]TypeError: 'question_text' is an invalid keyword argument for this function in django 2.0 tutorial
我對django相當陌生,我正在嘗試按照本教程( https://docs.djangoproject.com/en/2.0/intro/tutorial02/ )進行操作,但是遇到了以上錯誤。
這是我的models.py
代碼
import datetime
from django.db import models
from django.utils import timezone
# Create your models here.
class Question(models.Model):
question_text = models.CharField(max_length=200),
pub_date = models.DateTimeField('date published')
def __str__(self):
return self.question_text
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE),
choice_text = models.CharField(max_length=200),
votes = models.IntegerField(default=0)
def __str__(self):
return self.choice_text
另外,問題文本和選擇文本未出現在django-admin頁面上
在django中, modelname_somefieldname
是系統運算符語法,因此發生錯誤的原因是question_text
關鍵字包含question_
。 question
是型號名稱。
當您的表中沒有該字段時,會出現此錯誤。 如您所示,只有兩個字段被注冊( Id
, pub_date
)。 請進行遷移,如果仍然無法進行遷移,請刪除文件夾migrations
所有內容,然后再次進行遷移
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.