Missing Table When Running Django Unittest with Sqlite3

前端 未结 12 1879
半阙折子戏
半阙折子戏 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:02

    I had this problem, too. Turned out that I had to add a TEST_NAME property in the settings.py file to identify the test database properly. It solved the problem for me:

    if 'test' in sys.argv:
        DATABASES = {
            'default': {
                'ENGINE': 'django.db.backends.sqlite3',
                'NAME': os.path.join(os.path.dirname(__file__), 'test.db'),
                'TEST_NAME': os.path.join(os.path.dirname(__file__), 'test.db'),
           }
        }
    

提交回复
热议问题