Django中新应用程序的问题

时间:2011-03-23 12:21:18

标签: django django-models

我是Django的新手。我创建了一个名为“Directorio”的新应用程序,现在我需要验证SQL。

这是我的models.py

from django.db import models

class Directorio(models.Model):
    n_site = models.CharField(max_length=60)
    url = models.CharField(max_length=100)
    user_db_ins = models.CharField(max_lenght=50)
    user_db_upd = models.CharField(max_lenght=50)
    user_system_ins = models.CharField(max_lenght=50)
    user_system_upd = models.CharField(max_lenght=50)
    date_inserted = models.DateTimeField(auto_now_add=True)
    date_last_update = models.DateTimeField(auto_now=True)

这是我的settings.py INSTALLED APPS

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'directorio'
    # Uncomment the next line to enable the admin:
    # 'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
)

在此之后,我尝试使用以下命令验证SQL:

python manage.py sql directorio

我收到了这个错误:

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 219,
 in execute
    self.validate()
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 249,
 in validate
    num_errors = get_validation_errors(s, app)
  File "C:\Python27\lib\site-packages\django\core\management\validation.py", lin
e 36, 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, in
 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 im
port_module
    __import__(name)
  File "C:\xampp\htdocs\djangodir\directorio\models.py", line 3, in <module>
    class Directorio(models.Model):
  File "C:\xampp\htdocs\djangodir\directorio\models.py", line 6, in Directorio
    user_db_ins = models.CharField(max_lenght=50)
  File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py", line
 545, in __init__
    super(CharField, self).__init__(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'max_lenght'

我无法理解错误,有人能给我一些线索吗?

最诚挚的问候,

1 个答案:

答案 0 :(得分:2)

安德烈,

长度拼写为代码中的长度。请检查拼写错误。

user_db_ins = models.CharField(max_lenght=50)
user_db_upd = models.CharField(max_lenght=50)
user_system_ins = models.CharField(max_lenght=50)
user_system_upd = models.CharField(max_lenght=50)