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


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

查看所有标签

猜你喜欢:

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

ASP.NET动态网站开发基础教程

ASP.NET动态网站开发基础教程

郭兴峰 / 清华大学 / 2006-5 / 32.00元

ASP.NET是由Microsoft公司推出的新一代Web开发构架。开发人员可以通过ASP.NET实现动态网站的开发,包括开发Web应用程序和Web服务。   本书详细讲解了ASP.NET动态网站开发技术,共分13章,内容包括ASP.NET语言基础、HTML与Script语言、C#语言基础、ASP.NET常用对象、数据库访问技术、数据服务控件和数据绑定技术、ASP.NET配置和部署、ASP.......一起来看看 《ASP.NET动态网站开发基础教程》 这本书的介绍吧!

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

RGB HEX 互转工具

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

SHA 加密
SHA 加密

SHA 加密工具