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


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

查看所有标签

猜你喜欢:

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

PHP程序设计

PHP程序设计

勒道夫 / 陈浩、胡丹、徐景 / 电子工业出版社 / 2009-3 / 80.00元

《PHP程序设计(第2版)》是最新版本PHP 5的权威指南,其中包含创建者PHP的创建者 Rasmus Lerdorf的独到的见解。《PHP程序设计(第2版)》以一种清晰而简练的风格介绍了PHP语言的语法和程序设计技术,并通过大量的示例演示了它们的正确使用方法和习惯用法。《PHP程序设计(第2版)》还给出了设计风格提示和实际的程序设计建议,这些将帮助你不仅成为一个PHP程序员,而且将是出色的PHP......一起来看看 《PHP程序设计》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具