Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django测试-我只想创建一个数据库-如何指定_Django_Django Testing_Django Settings - Fatal编程技术网

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

Django测试-我只想创建一个数据库-如何指定,django,django-testing,django-settings,Django,Django Testing,Django Settings,因此,在my settings.py中,我指定了两个数据库连接(见下文) 但当我运行测试时,我只希望Django创建“默认”数据库 有没有办法做到这一点?我尝试添加TEST_CREATE:False选项,但我想这只是出于某种原因才适用于Oracle My settings.py代码段: DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2',

因此,在my settings.py中,我指定了两个数据库连接(见下文)

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

有没有办法做到这一点?我尝试添加TEST_CREATE:False选项,但我想这只是出于某种原因才适用于Oracle

My 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
    }

}

嗯,这里有一个方法。在设置正常数据库后,我将其添加到settings.py

if 'test' in sys.argv:
    DATABASES = {'default': {'ENGINE': 'django.db.backends.sqlite3',}}

可以查看设置中的sys.argv[1],查看您的数据库是否处于测试模式,并相应地设置数据库。