django 在内存中建立一个数据库用于测试选择的数据库引擎是否是sqlite3。但是,我需要将数据库放在文件系统上。如何更改设置以实现此目的?
最佳答案
根据documentation :
By default the test databases get their names by prepending test_ to the value of the NAME settings for the databases defined in DATABASES. When using the SQLite database engine the tests will by default use an in-memory database (i.e., the database will be created in memory, bypassing the filesystem entirely!). If you want to use a different database name, specify NAME in the TEST dictionary for any given database in DATABASES.
在 TEST
中指定 NAME
键词典:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
...
'TEST': {
'NAME': '/path/to/the/db/file'
}
}
}
请注意,对于 Django 1.6 及以下版本,您应该改为设置 TEST_NAME
:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
...
'TEST_NAME': '/path/to/the/db/file'
}
}
关于python - 如何设置 django 在单元测试期间不使用内存数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29044289/