读书人

django 1.3链接mysql数据库生成表,该怎

发布时间: 2012-02-16 21:30:36 作者: rapoo

django 1.3链接mysql数据库生成表
刚开始学习django ,使用的是“中文版django book”这本翻译的教材。
系统;windows 2003
python:2.6
django :1.3
msyql:5.1
在学习第5章 和数据库打交道“:数据建模 这章节
书中创建一个app.在models.py里面创建了三个表:出版商,书籍,作者。
当我在setting.py的
INSTALLED_APPS = (
#'django.contrib.auth',
#'django.contrib.contenttypes',
#'django.contrib.sessions',
#'django.contrib.sites',
#'django.contrib.messages',
#'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'mysite.books',
)

中添加了'mysite.books'之后,出现了下面大量错误

Python code
Validating models...Unhandled exception in thread started by <bound method Command.inner_run of <django.core.management.commands.runserver.Command object at 0x00D82770>>Traceback (most recent call last):  File "C:\Python26\Lib\site-packages\django\core\management\commands\runserver.py", line 88, in inner_run    self.validate(display_num_errors=True)  File "C:\Python26\Lib\site-packages\django\core\management\base.py", line 249, in validate    num_errors = get_validation_errors(s, app)  File "C:\Python26\Lib\site-packages\django\core\management\validation.py", line 36, in get_validation_errors    for (app_name, error) in get_app_errors().items():  File "C:\Python26\Lib\site-packages\django\db\models\loading.py", line 146, in get_app_errors    self._populate()  File "C:\Python26\Lib\site-packages\django\db\models\loading.py", line 61, in_populate    self.load_app(app_name, True)  File "C:\Python26\Lib\site-packages\django\db\models\loading.py", line 78, inload_app    models = import_module('.models', app_name)  File "C:\Python26\Lib\site-packages\django\utils\importlib.py", line 35, in import_module    __import__(name)  File "E:\mysite\..\mysite\books\models.py", line 2, in <module>    class Publisher(models.Model):  File "E:\mysite\..\mysite\books\models.py", line 3, in Publisher    name=models.CharField(maxlength=30)  File "C:\Python26\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 'maxlength'Validating models...Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x00D825B0>>Traceback (most recent call last):  File "C:\Python26\Lib\site-packages\django\core\management\commands\runserver.py", line 88, in inner_run    self.validate(display_num_errors=True)  File "C:\Python26\Lib\site-packages\django\core\management\base.py", line 249, in validate    num_errors = get_validation_errors(s, app)  File "C:\Python26\Lib\site-packages\django\core\management\validation.py", line 36, in get_validation_errors    for (app_name, error) in get_app_errors().items():  File "C:\Python26\Lib\site-packages\django\db\models\loading.py", line 146, in get_app_errors    self._populate()  File "C:\Python26\Lib\site-packages\django\db\models\loading.py", line 61, in_populate    self.load_app(app_name, True)  File "C:\Python26\Lib\site-packages\django\db\models\loading.py", line 78, inload_app    models = import_module('.models', app_name)  File "C:\Python26\Lib\site-packages\django\utils\importlib.py", line 35, in import_module    __import__(name)  File "E:\mysite\..\mysite\books\models.py", line 2, in <module>    class Publisher(models.Model):  File "E:\mysite\..\mysite\books\models.py", line 3, in Publisher    name=models.CharField(maxlength=30)  File "C:\Python26\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 'maxlength'E:\mysite>E:\mysite>python manage.py runserver 0.0.0.0:8080Validating models...Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x00D825B0>>Traceback (most recent call last):  File "C:\Python26\Lib\site-packages\django\core\management\commands\runserver.py", line 88, in inner_run    self.validate(display_num_errors=True)  File "C:\Python26\Lib\site-packages\django\core\management\base.py", line 249, in validate    num_errors = get_validation_errors(s, app)  File "C:\Python26\Lib\site-packages\django\core\management\validation.py", line 36, in get_validation_errors    for (app_name, error) in get_app_errors().items():  File "C:\Python26\Lib\site-packages\django\db\models\loading.py", line 146, in get_app_errors    self._populate()  File "C:\Python26\Lib\site-packages\django\db\models\loading.py", line 61, in_populate    self.load_app(app_name, True)  File "C:\Python26\Lib\site-packages\django\db\models\loading.py", line 78, inload_app    models = import_module('.models', app_name)  File "C:\Python26\Lib\site-packages\django\utils\importlib.py", line 35, in import_module    __import__(name)  File "E:\mysite\..\mysite\books\models.py", line 2, in <module>    class Publisher(models.Model):  File "E:\mysite\..\mysite\books\models.py", line 3, in Publisher    name=models.CharField(maxlength=30)  File "C:\Python26\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 'maxlength'Validating models...Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x00D825B0>>Traceback (most recent call last):  File "C:\Python26\Lib\site-packages\django\core\management\commands\runserver.py", line 88, in inner_run    self.validate(display_num_errors=True)  File "C:\Python26\Lib\site-packages\django\core\management\base.py", line 249, in validate    num_errors = get_validation_errors(s, app)  File "C:\Python26\Lib\site-packages\django\core\management\validation.py", line 36, in get_validation_errors    for (app_name, error) in get_app_errors().items():  File "C:\Python26\Lib\site-packages\django\db\models\loading.py", line 146, in get_app_errors    self._populate()  File "C:\Python26\Lib\site-packages\django\db\models\loading.py", line 61, in_populate    self.load_app(app_name, True)  File "C:\Python26\Lib\site-packages\django\db\models\loading.py", line 78, inload_app    models = import_module('.models', app_name)  File "C:\Python26\Lib\site-packages\django\utils\importlib.py", line 35, in import_module    __import__(name)  File "E:\mysite\..\mysite\books\models.py", line 2, in <module>    class Publisher(models.Model):  File "E:\mysite\..\mysite\books\models.py", line 3, in Publisher    name=models.CharField(maxlength=30)  File "C:\Python26\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 'maxlength'E:\mysite>python manage.py runserver 0.0.0.0:8080 >2.txtUnhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x00D83590>>Traceback (most recent call last):  File "C:\Python26\Lib\site-packages\django\core\management\commands\runserver.py", line 88, in inner_run    self.validate(display_num_errors=True)  File "C:\Python26\Lib\site-packages\django\core\management\base.py", line 249, in validate    num_errors = get_validation_errors(s, app)  File "C:\Python26\Lib\site-packages\django\core\management\validation.py", line 36, in get_validation_errors    for (app_name, error) in get_app_errors().items():  File "C:\Python26\Lib\site-packages\django\db\models\loading.py", line 146, in get_app_errors    self._populate()  File "C:\Python26\Lib\site-packages\django\db\models\loading.py", line 61, in_populate    self.load_app(app_name, True)  File "C:\Python26\Lib\site-packages\django\db\models\loading.py", line 78, inload_app    models = import_module('.models', app_name)  File "C:\Python26\Lib\site-packages\django\utils\importlib.py", line 35, in import_module    __import__(name)  File "E:\mysite\..\mysite\books\models.py", line 2, in <module>    class Publisher(models.Model):  File "E:\mysite\..\mysite\books\models.py", line 3, in Publisher    name=models.CharField(maxlength=30)  File "C:\Python26\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 'maxlength' 


请问有什么办法解决?
我可以确定是因为添加了'mysite.books'产生的。
books为产生的应用。
折磨啊!

[解决办法]
阅读出错信息啊。
出错信息已经明确告诉你了,maxlength是无法的参数名。再google下django CharField,一眼就能看到应该是max_length。
[解决办法]
无法->非法

读书人网 >perl python

热点推荐