[英]PyTest-Django Failing on missing django_migration table
我正在嘗試將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)
E OperationalError: no such table: django_migrations
ve/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py:485: OperationalError
我嘗試使用ensure_schema
中的conftest.py
創建表。 我嘗試了--nomigrations
和--create-db
到pytest
每個選項。
我猜這是舊系統遇到的一個奇怪的配置問題,但是我不確定從哪里開始尋找。 有人有建議嗎?
看起來可能是遷移問題。
運行./manage.py schemamigration research --auto
顯示大多數字段未指定任何默認值。
接下來,然后運行./manage.py schemamigration research --init
,然后運行./manage.py schemamigration research --init
./manage.py migrate research
創建表后,這對我有用:
python manage.py migrate --run-syncdb
注意:不要忘記先運行python makemigrations,即python manage.py makemigrations {name of the app where patients model is}
有用的提示:
django
生成了一個名為django_migrations
的表,該表可跟蹤已應用了哪些遷移。 如果刪除了migrations
,請重新生成它們並嘗試migrate
而不刪除表中的記錄,那么django
會認為它已經應用了它們。 您永遠不要刪除您的遷移,因為它會使django感到困惑。如果您正在積極進行開發,則可以跳過遷移步驟。如果您正在積極進行開發並希望跳過整個
migrations
系統,則可以,但是一旦開始使用migrations
,就不要刪除它們。 這是我在開發新項目時使用的:dropdb mydb && createdb mydb && python manage.py migrate --run-syncdb && python manage.py loaddata initial
首先,它刪除數據庫和所有數據。 然后創建一個空的。
--run-syncdb
生成模式,並且loaddata
從fixtures文件加載數據。因此,如果您仍在開發中並且可以刪除所有數據並將您關心的內容移至Fixture文件,則可以刪除所有遷移文件夾。 然后,您每次更改模型時都可以運行上面的命令。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.