我正在尝试学习django并设置一个mysql数据库 在settings.py中我做了这些更改
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'name',
'USER': 'root',
'PASSWORD': '****password****',
}
}
我在django 1.9中使用。如何使用我的mysql数据库,因为以下错误即将到来。
(project) C:\Users\soumyadeep dasgupta\Desktop\Project\src>python manage.py runs
erver
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
(project) C:\Users\soumyadeep dasgupta\Desktop\Project\src>pip install MySQL-pyt
hon
Requirement already satisfied (use --upgrade to upgrade): MySQL-python in c:\use
rs\soumya~1\envs\project\lib\site-packages\mysql_python-1.2.3-py2.7-win32.egg
(project) C:\Users\soumyadeep dasgupta\Desktop\Project\src>python manage.py sync
db
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
在虚拟环境中再次安装djano解决了这个错误
(project) C:\Users\soumyadeep dasgupta\Desktop\Project\src>python manage.py sync
db
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\SOUMYA~1\Envs\project\lib\site-packages\django\core\management\
__init__.py", line 353, in execute_from_command_line
utility.execute()
File "C:\Users\SOUMYA~1\Envs\project\lib\site-packages\django\core\management\
__init__.py", line 327, in execute
django.setup()
File "C:\Users\SOUMYA~1\Envs\project\lib\site-packages\django\__init__.py", li
ne 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\SOUMYA~1\Envs\project\lib\site-packages\django\apps\registry.py
", line 108, in populate
app_config.import_models(all_models)
File "C:\Users\SOUMYA~1\Envs\project\lib\site-packages\django\apps\config.py",
line 202, in import_models
self.models_module = import_module(models_module_name)
File "c:\python27\Lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "C:\Users\SOUMYA~1\Envs\project\lib\site-packages\django\contrib\auth\mod
els.py", line 4, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "C:\Users\SOUMYA~1\Envs\project\lib\site-packages\django\contrib\auth\bas
e_user.py", line 49, in <module>
class AbstractBaseUser(models.Model):
File "C:\Users\SOUMYA~1\Envs\project\lib\site-packages\django\db\models\base.p
y", line 108, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "C:\Users\SOUMYA~1\Envs\project\lib\site-packages\django\db\models\base.p
y", line 307, in add_to_class
value.contribute_to_class(cls, name)
File "C:\Users\SOUMYA~1\Envs\project\lib\site-packages\django\db\models\option
s.py", line 263, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length(
))
File "C:\Users\SOUMYA~1\Envs\project\lib\site-packages\django\db\__init__.py",
line 36, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\Users\SOUMYA~1\Envs\project\lib\site-packages\django\db\utils.py", li
ne 212, in __getitem__
backend = load_backend(db['ENGINE'])
File "C:\Users\SOUMYA~1\Envs\project\lib\site-packages\django\db\utils.py", li
ne 116, in load_backend
return import_module('%s.base' % backend_name)
File "c:\python27\Lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "C:\Users\SOUMYA~1\Envs\project\lib\site-packages\django\db\backends\mysq
l\base.py", line 28, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: DLL l
oad failed: %1 is not a valid Win32 application.