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

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

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


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

查看所有标签

猜你喜欢:

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

JAVASCRIPT语言精髓与编程实践

JAVASCRIPT语言精髓与编程实践

周爱民 / 电子工业出版社 / 2008-3 / 68.00元

《JAVASCRIPT语言精髓与编程实践》讲述了JavaScript的语言实现与扩展,主要包括以下三个方面的内容:(1)动态、函数式语言,以及其它语言特性在JavaScript的表现与应用;(2)如何用动态函数式语言的特性来扩展JavaScript的语言特性与框架;(3)如何将JavaScript引擎整合到其它高级语言的开发过程中。一起来看看 《JAVASCRIPT语言精髓与编程实践》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

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

HSV CMYK互换工具