5

First of all, I'm new to asking question here, so bear with me if I don't do it perfectly :) Here goes...

I am setting up a Django2.0 API that is going to deal with statistics. It has its own 'default' database to write stuff obviously, but I am going to need several other databases that will be read-only. This is what the settings look like for now.

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',
    },
}

When fabric deploys the project into staging, part of the routine is ./manage.py test, which leads to the following error:

(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

It makes total sense considering other_db_user is a read-only user, so I would like to disable django's testing for this database. Is there a clean way to do it ? Also, this stats app is going to be linked with quite a few databases later on, so I would rather use a solution that's easy to scale.

Thanks in advance for any tip you will throw my way !

edit: just to clarify, I need to access the read_only databases when testing, but django shouldn't create test_databases, it should use the staging ones it is given :)

  • You can make `test_settings.py` as a settings file. – Willem Van Onsem Aug 26 '18 at 09:56
  • Furthermore looks like a perfect question! :) – Willem Van Onsem Aug 26 '18 at 09:56
  • Hi @WillemVanOnsem, and thank you for the VERY fast answer. However, I am not sure I understand what you want me to do. Should I duplicate my `settings.py` into a `test_settings.py` and delete extra databases from there ? If so, how do I write tests that read into those read-only databases ? I just noticed my question said I wanted to disable django testing, but what I think I want is to disable is django **creating a test database**, I'll try and edit my question accordingly. :) – Vincent Charles Aug 26 '18 at 10:00

0 Answers0