首页 > 解决方案 > Django 数据库问题

问题描述

您好,我的 Django 数据库出现问题。

这是我的 settings.py

    DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'MConDb',
        'USER': 'postgres',
        'PASSWORD': 'KODOkona880,',
        'HOST': 'localhost',
        'PORT': 5432,
    }
}

这是我得到的错误。

    conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: FATAL:  database "MConDb" does not exist

这是 postgres 中的命令 \l 显示的列表

         Name         |  Owner   | Encoding |          Collate           |           Ctype            |   Access privileges
----------------------+----------+----------+----------------------------+---
 django               | postgres | UTF8     | English_United States.1252 | English_United States.1252 |
 mcondb               | postgres | UTF8     | English_United States.1252 | English_United States.1252 |
 postgres             | postgres | UTF8     | English_United States.1252 | English_United States.1252 |

希望你能帮助我,我将非常感激谢谢。

标签: djangopostgresql

解决方案


您的数据库名称全是小写字母mcondb | postgr..,那您为什么要使用'NAME': 'MConDb'

试试这个 :

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'mcondb',
        'USER': 'postgres',
        'PASSWORD': 'KODOkona880,',
        'HOST': 'localhost',
        'PORT': 5432,
    }
}

您确定您的密码包含,结尾吗?请确认。


推荐阅读