(我在 django 1.6 上使用 python2.7.6)
我已经使用 django 创建了一个应用程序调用注册,当我使用 sqlite 时我可以毫无问题地执行 python manage.py syncdb 但现在我使用 mysql 我收到此消息:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 284, in execute
self.validate()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 310, in validate
num_errors = get_validation_errors(s, app)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/validation.py", line 34, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 196, in get_app_errors
self._populate()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 75, in _populate
self.load_app(app_name, True)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 99, in load_app
models = import_module('%s.models' % app_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/var/www/firstweb/signups/models.py", line 6, in <module>
class SignUp(models.Model):
File "/var/www/firstweb/signups/models.py", line 7, in SignUp
first_name = models.CharField(max_lenght=255, null=True, blank=True)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py", line 685, in __init__
super(CharField, self).__init__(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'max_lenght'
这是我在 models.py 中的应用:
from django.db import models
from django.utils.encoding import smart_unicode
# Create your models here.
class SignUp(models.Model):
first_name = models.CharField(max_lenght=255, null=True, blank=True)
last_name = models.CharField(max_lenght=255, null=True, blank=True)
email = models.EmailField()
timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
updated = models.DateTimeField(auto_now_add=False, auto_now=True)
def __unicode__(self):
return smart_unicode(self.email)
最佳答案
您只是打错了字:使用“max_length”而不是“max_lenght”:
class SignUp(models.Model):
first_name = models.CharField(max_length=255, null=True, blank=True)
last_name = models.CharField(max_length=255, null=True, blank=True)
email = models.EmailField()
timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
updated = models.DateTimeField(auto_now_add=False, auto_now=True)
def __unicode__(self):
return smart_unicode(self.email)
关于python - 使用mysql syncdb错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23197943/