几周前我使用Django 我开始使用django应用程序并在model.py
中编写这些行 from django.db import models
class Publisher(models.Model):
name = models.CharField(max_length=30)
address = models.CharField(max_lenght=50)
city = models.CharField(max_length=60)
state_province = models.CharField(max_length=30)
country = models.model.CharField(max_length=50)
website = models.URLField()
class Author(models.Model):
first_name = models.CharFiled(max_length=30)
last_name = models.CharField(max_length=40)
email = models.EmailField()
class Book(models.Model):
title = models.CharField(max_length=100)
authors = models.ManyToManyField(Author)
publisher = models.ForeignKey(Publisher)
publication_date = models.DateField()
当我尝试验证或sqlall
时python manage.py validate
or
python manage.py sqlall appname
它会打印此错误消息
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
438, in execute_manager
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 191
in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 218
in execute
output = self.handle(*args, **options)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 347
in handle
return self.handle_noargs(**options)
File "C:\Python27\lib\site-packages\django\core\management\commands\validate.
y", line 9, in handle_noargs
self.validate(display_num_errors=True)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 245
in validate
num_errors = get_validation_errors(s, app)
File "C:\Python27\lib\site-packages\django\core\management\validation.py", li
e 28, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 146, i
get_app_errors
self._populate()
File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 61, in
_populate
self.load_app(app_name, True)
File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 78, in
load_app
models = import_module('.models', app_name)
File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in i
port_module
__import__(name)
File "C:\Documents and Settings\root\mysite\..\mysite\books\models.py", line
, in <module>
class Publisher(models.Model):
File "C:\Documents and Settings\root\mysite\..\mysite\books\models.py", line
, in Publisher
address = models.CharField(max_lenght=50)
File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py", lin
542, in __init__
super(CharField, self).__init__(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'max_lenght'
请帮我解决此错误
答案 0 :(得分:9)
不想粗鲁,但你是否懒得阅读错误信息?
unexpected keyword argument 'max_lenght'
(你拼错了max_length
)
编辑:
大量的错误消息可能令人生畏,但第一行有一个很好的提示:
Traceback (most recent call last):
从底部开始查看,确实可以找到您的错误。
另一个提示(虽然这次没有帮助)是扫描代码中是否存在您编写的文件中的错误(而不是django库代码),这有时位于列表的中间。
答案 1 :(得分:3)
异常消息不能更清楚:
TypeError: __init__() got an unexpected keyword argument 'max_lenght'
这是违规行,看起来像是一个错字。
address = models.CharField(max_lenght=50)
^