Missing Table When Running Django Unittest with Sqlite3

前端 未结 12 1878
半阙折子戏
半阙折子戏 2021-01-03 23:42

I\'m trying to run a unittest with Django 1.3. Normally, I use MySQL as my database backend, but since this is painfully slow to spinup for a single unittest, I\'m using Sql

12条回答
  •  天命终不由人
    2021-01-04 00:01

    For anyone that will get here, searching for why Django keeps creating a database regardless of the --keepdb option. Why it says Using existing test database for alias 'default', but then runs a bunch of CREATE TABLE statements.

    If you don't set a DATABASES > default > TEST > NAME setting, Django will try to use in memory database, and it wont be kept, so set this and override a defaults.

    You can make it like this:

    DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(ROOT_DIR, 'data', 'db.dev.sqlite3'), 'TEST': { 'NAME': os.path.join(ROOT_DIR, 'data', 'db.test.sqlite3'), } } }

提交回复
热议问题