python – PyTest-Django在缺少django_migration表時失敗
我試圖新增pytest-django到我目前的pytest3 / Django1.7環境.
目前我們沒有使用外掛,並且在某些測試之間遭受共享狀態
一切似乎在視覺上看起來都很好,測試似乎通過,直到結束當我收到以下錯誤資訊:
request = <SubRequest '_django_db_marker' for <Function 'test_filter_recurring_outside_sync_window'>> @pytest.fixture(autouse=True) def _django_db_marker(request): """Implement the django_db marker, internal to pytest-django. This will dynamically request the ``db`` or ``transactional_db`` fixtures as required by the django_db marker. """ marker = request.keywords.get('django_db', None) if marker: validate_django_db(marker) if marker.transaction: getfixturevalue(request, 'transactional_db') else: getfixturevalue(request, 'db') ve/lib/python2.7/site-packages/pytest_django/plugin.py:376: self = <django.db.backends.sqlite3.base.SQLiteCursorWrapper object at 0x11976a478> query = 'SELECT "django_migrations"."app", "django_migrations"."name" FROM "django_migrations"', params = () def execute(self, query, params=None): if params is None: return Database.Cursor.execute(self, query) query = self.convert_query(query) >return Database.Cursor.execute(self, query, params) EOperationalError: no such table: django_migrations ve/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py:485: OperationalError
我嘗試在conftest.py中使用ensure_schema建立表.
我嘗試過–nomigrations的每個選項,–create-db到pytest.
我猜這是一個古怪的配置問題,我有一個遺留的系統,但我不知道從哪裡開始尋找.有人有建議嗎?
看起來可能是遷移的問題.
執行./manage.py schemamigration研究–auto顯示大多數字段沒有指定任何預設值.
接下來,然後執行./manage.py schemamigration研究–init,然後執行./manage.py遷移研究
這在我建立表後對我有用:
python manage.py migrate --run-syncdb
注意:不要忘記首先執行python makemigrations,即python manage.py makemigrations {患者型號的應用程式名稱}
Helpful tips:There is a table generated bydjango
calleddjango_migrations
which keeps track of what migrations have
been
applied. If you delete yourmigrations
, re-generate them and try to
migrate
without deleting the records from the table, thendjango
will
think it already applied them. You should never delete your
migrations, as it will cause django to get confused.
migrations
system you can, but once you start usingmigrations
, never delete
them. Here is what I use while developing a new project:
dropdb mydb && createdb mydb && python manage.py migrate --run-syncdb && python manage.py loaddata initial
首先,它會丟棄資料庫和所有資料.然後它建立一個空的
一. –run-syncdb生成架構並載入loaddata
資料來自ofollow,noindex" target="_blank">fixtures file .
所以,如果你仍在開發並且可以刪除所有的資料並移動
你關心的燈具檔案,那麼你可以刪除所有你
遷移資料夾.然後,您可以在每次更改時執行命令
模型.
http://stackoverflow.com/questions/41770334/pytest-django-failing-on-missing-django-migration-table