python – PyTest-Django在缺少django_migration表时失败

栏目: Python · 发布时间: 7年前

内容简介: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.

You can skip the migrations step if you are actively developing If you are actively developing and want to skip the entire 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


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

分布式服务架构:原理、设计与实战

分布式服务架构:原理、设计与实战

李艳鹏、杨彪 / 电子工业出版社 / 2017-8 / 89.00

《分布式服务架构:原理、设计与实战》全面介绍了分布式服务架构的原理与设计,并结合作者在实施微服务架构过程中的实践经验,总结了保障线上服务健康、可靠的最佳方案,是一本架构级、实战型的重量级著作。 《分布式服务架构:原理、设计与实战》以分布式服务架构的设计与实现为主线,由浅入深地介绍了分布式服务架构的方方面面,主要包括理论和实践两部分。理论上,首先介绍了服务架构的背景,以及从服务化架构到微服务架......一起来看看 《分布式服务架构:原理、设计与实战》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具