问题
I'm trying to use django selenium for testing my django1.3 application. The database backend for the testing is sqlite3.
Here is a snippet of my settings file.
if 'test' in sys.argv:
DB_ENGINE = 'django.db.backends.sqlite3'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'TEST_NAME': ':memory:',
'NAME': 'database_one',
},
'database_two': {
'ENGINE': 'django.db.backends.sqlite3', ]
'TEST_NAME': ':memory:',
'NAME': 'database_two',
},
'database_three': {
'ENGINE': 'django.db.backends.sqlite3',
'TEST_NAME': ':memory:',
'NAME': 'database_three',
},
}
SOUTH_TESTS_MIGRATE = False
When I run the selenium tests, I get the error saying
DatabaseError: no such table: django_session
ERROR
As a matter of fact it shows up during test creation that the tables are created in the output as follows,
Creating test database for alias 'default' (':memory:')...
Creating tables ...
Creating table django_content_type
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_user_permissions
Creating table auth_user_groups
Creating table auth_user
Creating table auth_message
Creating table django_session
I am literally stuck here as I cannot find anything about this elsewhere.
PS: The test work fine in postgres (my actual prod db engine) but I want to use sqlite3 as postgres takes a lot of time to setup & teardown db when running tests..
Thanks in advance :)
回答1:
If its in memory(like in your example), the second its closed, the data disappears.
Make an actual db file, that will solve the problem. You can do this by simply giving the absolute path to the file, if there does not happen to be one, it will create one for you.
来源:https://stackoverflow.com/questions/17703046/databaseerror-no-such-table-django-session-error-during-django-1-3-selenium