内容简介:http://stackoverflow.com/questions/41770334/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
我尝试在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 by django
called django_migrations
which keeps track of what migrations have
been
applied. If you delete your migrations
, re-generate them and try to
migrate
without deleting the records from the table, then django
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 using migrations
, 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
数据来自 fixtures file .
所以,如果你仍在开发并且可以删除所有的数据并移动
你关心的灯具文件,那么你可以删除所有你
迁移文件夹.然后,您可以在每次更改时运行命令
模型.
http://stackoverflow.com/questions/41770334/pytest-django-failing-on-missing-django-migration-table
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- Xcode 10 缺少 libstdc++ 库的处理
- 修复:Windows10上缺少Mfplat.dll
- redhat 7安装Oracle缺少compat-libstdc++
- ruby – 缺少mysql2 gem.将它添加到您的Gemfile:gem’mysql2′
- GO有语法缺陷,缺少泛型、public/private、三元运算符?我不喜欢 Go 语言的十个理由
- 快速失败机制 & 失败安全机制
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
The Nature of Code
Daniel Shiffman / The Nature of Code / 2012-12-13 / GBP 19.95
How can we capture the unpredictable evolutionary and emergent properties of nature in software? How can understanding the mathematical principles behind our physical world help us to create digital w......一起来看看 《The Nature of Code》 这本书的介绍吧!