错误是:没有名为postgresql.base的模块

时间:2016-02-25 22:06:18

标签: python django postgresql

我正在尝试将Django应用程序迁移到postgresql,但是我无法让Django认识到实际安装了postgres。我已将它安装在我的计算机上,并且它在我的计算机上正常运行,但当我尝试将其设置为FileOutputStream destinationDir = new FileOutputStream(sdCard.getAbsolutePath() + "/Download/Dir/nwdLogs.zip"); ZipOutputStream out = new ZipOutputStream(destinationDir); currentZipFileSize = 0; addDirToArchive(out, destinationDir, dirName); out.close(); destinationDir.close(); 中的默认值时,我收到错误:

  

错误是:没有名为postgresql.base的模块

我在使用Django herehere运行postgresql时经历了两次演练,但我仍然遇到此错误。我应该在我的虚拟环境中安装postgresql吗?我试过这样做,但没有运气。

settings.py

settings.py

完整追溯

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

1 个答案:

答案 0 :(得分:6)

所以我得到的堆栈跟踪几乎与上面相同。所以我运行了以下内容:

pip install psycopg2

之后,堆栈跟踪更改为

django.core.exceptions.ImproperlyConfigured: 'django.db.backends.postgresql' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
    u'base', u'mysql', u'oracle', u'postgresql_psycopg2', u'sqlite3'
Error was: No module named postgresql.base

然后我打开了我的settings.py文件并按照上面的堆栈跟踪中的建议更改了数据库后端

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'database',
        'USER': 'username',
        'PASSWORD': 'password',
        'HOST': '127.0.0.1',
        'PORT': '5432',
    }
}

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'database',
        'USER': 'username',
        'PASSWORD': 'password',
        'HOST': '127.0.0.1',
        'PORT': '5432',
    }
}

该应用程序设法连接!从How to setup PostgreSQL Database in Django?

获取信息