[英]how do I fix CharField attribute error in django?
I am a beginner and this might seem very trivial to most. 我是一个初学者,这对大多数人来说似乎很琐碎。 I am getting an the following error: 我收到以下错误:
Traceback (most recent call last): File "C:\\Dev\\hoss\\myfirst\\app_one\\models.py", line 3, in class Question(models.Model): File "C:\\Dev\\hoss\\myfirst\\app_one\\models.py", line 5, in Question textone = models.CharField(max_lenght=128) File "C:\\Dev\\hoss\\lib\\site-packages\\django\\db\\models\\fields__init__.py", line 1037, in init super(). 追溯(最近一次通话):文件“ C:\\ Dev \\ hoss \\ myfirst \\ app_one \\ models.py”,第3行,在类Question(models.Model)中:文件“ C:\\ Dev \\ hoss \\ myfirst \\ app_one \\ models.py“,第5行,在问题中textone = models.CharField(max_lenght = 128)文件” C:\\ Dev \\ hoss \\ lib \\ site-packages \\ django \\ db \\ models \\ fields__init __。py“,第1037行,在init super()中。 init (*args, **kwargs) TypeError: init () got an unexpected keyword argument 'max_lenght' init (* args,** kwargs)TypeError: init ()获得了意外的关键字参数'max_lenght'
for the following code and cant fix it any body can help: 对于以下代码,无法解决它,任何机构都可以帮助您:
from django.db import models
class Question(models.Model):
textone = models.CharField(max_lenght=128)
pub_date = models.DateTimeField()
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete = models.CASCADE)
text = models.CharField(max_lenght=200)
vote = models.IntegerField(default = 0)
There is a typo in your code. 您的代码中有一个错字。 textone =models.CharField(max_lenght=128)
it should be textone =models.CharField(max_length=128)
and text = models.CharField(max_lenght=200)
, it should be text = models.CharField(max_length=200)
textone =models.CharField(max_lenght=128)
应该是textone =models.CharField(max_length=128)
和text = models.CharField(max_lenght=200)
,应该是text = models.CharField(max_length=200)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.