Missing Table When Running Django Unittest with Sqlite3

前端 未结 12 1792
半阙折子戏
半阙折子戏 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-03 23:51

    Having tried all of the above I eventually discovered another reason this can happen:-

    If any of your models are not created by one of your migrations.

    I did some debugging and it seems that Django testing sets up the database by applying all your migrations in order, starting with 001_initial.py, before trying to SELECT from the tables based on your models.py

    In my case a table had somehow not been added to the migrations, but added manually, so the full migration set couldn't be properly applied. When I manually fixed the 001_initial.py migration to create this table the OperationalError went away.

提交回复
热议问题