ImportError:Ubuntu 11.04 服务器上的 django 项目中没有名为 mysql.base 的模块
我按照 Django Book 中的步骤进行操作,并到达作者解释的部分我建立了一个django项目来使用数据库。我选择了mysql。
我在 settings.py
中的设置是:
DATABASES = {
'default': {
'ENGINE': 'mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'mydatabase', # Or path to database file if using sqlite3.
'USER': 'myname', # Not used with sqlite3.
'PASSWORD': 'mypassword', # 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.
}
}
当尝试启动服务器时,会打印以下消息:
Validating models...
Traceback (most recent call last):
File "/home/me/workspace/mysite/src/mysite/manage.py", line 14, in <module>
execute_manager(settings)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 442, in execute_manager
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 379, 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 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 67, in handle
self.run(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 78, in run
self.inner_run(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 88, in inner_run
self.validate(display_num_errors=True)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 243, in validate
from django.core.management.validation import get_validation_errors
File "/usr/local/lib/python2.7/dist-packages/django/core/management/validation.py", line 3, in <module>
from django.contrib.contenttypes.generic import GenericForeignKey, GenericRelation
File "/usr/local/lib/python2.7/dist-packages/django/contrib/contenttypes/generic.py", line 7, in <module>
from django.db import connection
File "/usr/local/lib/python2.7/dist-packages/django/db/__init__.py", line 27, in <module>
connection = connections[DEFAULT_DB_ALIAS]
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 81, in __getitem__
backend = load_backend(db['ENGINE'])
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 23, in load_backend
return import_module('.base', backend_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
ImportError: No module named mysql.base
我用谷歌搜索了一下,发现如果您使用旧版本的 MySQLd,则可以打印此消息。所以我确保我获得了最新版本。并在交互式 python shell 中测试了导入。没关系。
还有其他建议吗,为什么这不起作用?
我正在开发一个新安装的 Ubuntu 11.04 版本(Windows 7 中的 Wubi),如果这很重要的话。 =)
I am following the steps in the Django Book and got to the part where the authors explain hot wo set up a django project to use a database. I chose mysql.
My settings in settings.py
are:
DATABASES = {
'default': {
'ENGINE': 'mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'mydatabase', # Or path to database file if using sqlite3.
'USER': 'myname', # Not used with sqlite3.
'PASSWORD': 'mypassword', # 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.
}
}
When trying to start the server, the following message is printed:
Validating models...
Traceback (most recent call last):
File "/home/me/workspace/mysite/src/mysite/manage.py", line 14, in <module>
execute_manager(settings)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 442, in execute_manager
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 379, 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 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 67, in handle
self.run(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 78, in run
self.inner_run(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 88, in inner_run
self.validate(display_num_errors=True)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 243, in validate
from django.core.management.validation import get_validation_errors
File "/usr/local/lib/python2.7/dist-packages/django/core/management/validation.py", line 3, in <module>
from django.contrib.contenttypes.generic import GenericForeignKey, GenericRelation
File "/usr/local/lib/python2.7/dist-packages/django/contrib/contenttypes/generic.py", line 7, in <module>
from django.db import connection
File "/usr/local/lib/python2.7/dist-packages/django/db/__init__.py", line 27, in <module>
connection = connections[DEFAULT_DB_ALIAS]
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 81, in __getitem__
backend = load_backend(db['ENGINE'])
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 23, in load_backend
return import_module('.base', backend_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
ImportError: No module named mysql.base
I googled a little and found out, that this message could be printed if you use an older version of MySQLd. So I made sure I got the latest version. And tested the import in an interactive python shell. It's fine.
Any other suggestions, why this doesn't work?
I am working on a fresh installed Ubuntu 11.04 Version (Wubi in Windows 7), if that matters. =)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正确的数据库设置是
'django. db.backends.mysql'
。The correct database setting is
'django.db.backends.mysql'
.