Django 报错TypeError: __init__() got an unexpected keyword argument ‘maxlength’解决

model.py内容如下:

class Publisher(models.Model):

name = models.CharField(maxlength=30)
address = models.CharField(maxlength=50)
city = models.CharField(maxlength=60)
state_province = models.CharField(maxlength=30)
country = models.CharField(maxlength=50)
website = models.URLField()

执行python manage.py  validate(这个命令是检查模型是否存在异常的)报错。

TypeError: __init__() got an unexpected keyword argument ‘maxlength’

Django下出现这个错误,记录一下,貌似以前的版本是应该用maxlength,但是新版本里面使用max_length

修改models.py

class Publisher(models.Model):
name = models.CharField(max_length=30)
address = models.CharField(max_length=50)
city = models.CharField(max_length=60)
state_province = models.CharField(max_length=30)
country = models.CharField(max_length=50)
website = models.URLField()

root@ubuntu:/home/kerwin/python/Django/project/myweb# python manage.py validate
0 errors found

解决了TypeError: __init__() got an unexpected keyword argument ‘maxlength’报错。

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>