我是django和python的新手,尝试在我的系统上运行一段django代码,但我遇到了这些问题,即运行版本2.7 python和v1.4 django
$ python manage.py runserver
Running in development mode.
Running in development mode.
Running in development mode.
Running in development mode.
Validating models...
HACKUING USER MODEL
Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x101981e50>>
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 91, in inner_run
self.validate(display_num_errors=True)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/validation.py", line 30, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/loading.py", line 158, in get_app_errors
self._populate()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/loading.py", line 64, in _populate
self.load_app(app_name, True)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/loading.py", line 88, in load_app
models = import_module('.models', app_name)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/Kinnovate/Desktop/fsdjango/platformsite/notices/models.py", line 9, in <module>
from common.fields import PickleField
File "/Users/Kinnovate/Desktop/fsdjango/platformsite/common/fields/__init__.py", line 1, in <module>
from pickle import *
File "/Users/Kinnovate/Desktop/fsdjango/platformsite/common/fields/pickle.py", line 27, in <module>
mysql_backend = settings.DATABASE_ENGINE == 'mysql'
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/functional.py", line 186, in inner
return func(self._wrapped, *args)
AttributeError: 'Settings' object has no attribute 'DATABASE_ENGINE'
这是与问题
相关的settings.py的一部分DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': os.path.join(DIRNAME, 'database.sqlite3'), # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
我该如何解决这个问题?
答案 0 :(得分:6)
什么是/Users/Kinnovate/Desktop/fsdjango/platformsite/common/fields/pickle.py
?这是你的代码吗?然后你有一个错误,因为你的seetings中确实没有DATABASE_ENGINE
。请改用settings.DATABASES['default']['ENGINE']
。
答案 1 :(得分:1)
你遗失了什么
因为您的回溯数据库必须是mysql
。
File "/Users/Kinnovate/Desktop/fsdjango/platformsite/common/fields/pickle.py", line 27, in <module>
mysql_backend = settings.DATABASE_ENGINE == 'mysql'
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/functional.py", line 186, in inner
return func(self._wrapped, *args)
因为它输入mysql_backend = settings.DATABASE_ENGINE == 'mysql'
行。
根据您的设置'ENGINE': 'django.db.backends.sqlite3',
,因此必须输入sqlite
,请检查您的应用,因为您的settings.py
可能会从其他地方引荐。