配置不正确的数据库后端django和mysql

时间:2017-08-23 15:45:53

标签: python mysql django database backend

我刚刚克隆了一个repo,当我尝试运行我的python应用程序时,我收到以下错误:

Traceback (most recent call last):   
    File "/Library/Python/2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
        fn(*args, **kwargs)   
    File "/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py", line 116, in inner_run
        self.check(display_num_errors=True)   
    File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 426, in check
        include_deployment_checks=include_deployment_checks,   
    File "/Library/Python/2.7/site-packages/django/core/checks/registry.py", line 75, in run_checks
        new_errors = check(app_configs=app_configs)   
    File "/Library/Python/2.7/site-packages/django/core/checks/model_checks.py", line 28, in check_all_models
        errors.extend(model.check(**kwargs))   
    File "/Library/Python/2.7/site-packages/django/db/models/base.py", line 1172, in check
        errors.extend(cls._check_long_column_names())   
    File "/Library/Python/2.7/site-packages/django/db/models/base.py", line 1587, in _check_long_column_names
        connection = connections[db]   
    File "/Library/Python/2.7/site-packages/django/db/utils.py", line 212, in
__getitem__
        backend = load_backend(db['ENGINE'])   
    File "/Library/Python/2.7/site-packages/django/db/utils.py", line 135, in load_backend
        raise ImproperlyConfigured(error_msg) django.core.exceptions.ImproperlyConfigured: 'sql_server.pyodbc' isn't an available database backend. Try using 'django.db.backends.XXX', where XXX is one of:

    'mysql', 'oracle', 'postgresql', 'sqlite3' 
Error was: No module named sql_server.pyodbc.base

我不确定我错过了什么设置。我检查了mysql,数据库存在于那里

mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| mydb               |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

我的设置文件看起来像这样

DATABASES = {

    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'mydb',
        'USER': 'dbuser',
        'PASSWORD': 'dbpassword',
        'HOST': '127.0.0.1',
        'PORT': '3306',
        'OPTIONS' : {
        'sql_mode': 'ANSI',
        "init_command": "SET foreign_key_checks = 0;"},

        },
}

...

编辑:

我有另一个数据库如下

'db2': {
        'NAME': 'db2',
        'ENGINE': 'sql_server.pyodbc',
        .......
    },  

当我将此ENGINE更改为django.db.backends.mysql时,它似乎有效。好像我在安装这个问题时遇到了问题...

0 个答案:

没有答案