Django测试 - 我只想创建一个我的数据库 - 如何指定

Gre*_*reg 3 django django-testing django-settings

所以在我的settings.py中我指定了两个数据库连接(见下文).

但是当我运行测试时,我只希望Django创建"默认"数据库.

有没有办法做到这一点?我尝试添加TEST_CREATE:False选项,但我想这只是因为某些原因而导致的Oracle?

我的settings.py片段:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'App1',                      # Or path to database file if using sqlite3.
        'USER': 'webaccess',                      # Not used with sqlite3.
        'PASSWORD': '***',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    },
    'default_root': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'App1',                      # Or path to database file if using sqlite3.
        'USER': 'django',                      # Not used with sqlite3.
        'PASSWORD': '****',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
        'TEST_CREATE': False            #Don't create when testing
    }

}
Run Code Online (Sandbox Code Playgroud)

Gre*_*reg 6

嗯,这是一种方法.我在设置普通数据库后将其添加到settings.py中.

if 'test' in sys.argv:
    DATABASES = {'default': {'ENGINE': 'django.db.backends.sqlite3',}}
Run Code Online (Sandbox Code Playgroud)