3

所以在我的 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
    }

}
4

1 回答 1

7

好吧,这是一种方法。在设置了我的普通数据库后,我将它添加到了 settings.py 中。

if 'test' in sys.argv:
    DATABASES = {'default': {'ENGINE': 'django.db.backends.sqlite3',}}
于 2012-05-11T14:53:42.433 回答