Django 2.0-当我们有多个数据库时,如何只对一个数据库进行测试?

时间:2018-08-26 09:51:15

标签: django django-database django-tests

首先,我是在这里问问题的新手,所以如果我做得不够好,请忍受我的意思:)这儿...

我正在设置要处理统计信息的Django2.0 API。它有自己的“默认”数据库来显然地编写内容,但是我将需要其他几个只读数据库。这就是现在的设置。

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'dev_gpws',
        'USER': 'dev_gpws_user',
        'PASSWORD': 'gpws_pwd',
        'HOST': 'localhost',
        'PORT': '5432',
    },
    'other_db': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'other_db_name',
        'USER': 'other_db_user',
        'PASSWORD': 'other_db_pwd',
        'HOST': 'other_db_host',
        'PORT': '5432',
    },
}

当结构将项目部署到暂存环境中时,例程的一部分为./manage.py test,这将导致以下错误:

(gpws) dev_gpws@af968cdb7653:~/gpws/project$ ./manage.py test
Creating test database for alias 'default'...
Creating test database for alias 'other_db'...
Got an error creating the test database: ERREUR:  permission denied to create database

考虑到other_db_user是只读用户,这是完全有意义的,因此我想对此数据库禁用django的测试。有没有一种干净的方法?另外,此统计应用程序稍后将与许多数据库链接,因此,我宁愿使用易于扩展的解决方案。

在此先感谢您给我的提示!

编辑: 只是为了澄清,测试时我需要访问只读数据库,但是django不应创建test_database,它应使用指定的暂存数据库:)

0 个答案:

没有答案