在Django项目中无法使用South加载固定装置 [英] Couldn't load fixtures with South in Django project

查看:168
本文介绍了在Django项目中无法使用South加载固定装置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Django项目,它正在使用South应用程序来处理模式和数据迁移。在我的一个应用程序中,我有一个迁移(号码0004)负责从json文件中加载数据夹具:

  class Migration数据迁移)

def forward(self,orm):
from django.core.management import call_command
call_command(loaddata,dummy_data.json)$ b $在同一个项目中,我尝试添加软删除的功能,需要添加一个以上的文件,定义为:



  deleted_at = models.DateTimeField(blank = True,null = True)
/ pre>

根据此更改,我添加了新的迁移,其数量为0009.之后,我开始迁移命令,给我错误:

  DatabaseError:安装fixture的问题C:/ Users / Grzegorz / PycharmProjects / Dummy Project / Dummy\app_subapp\fixtures \dummy_data.json':无法加载app_subapp.DummyData(pk = 1):(1054,未知列deleted_a t'in'field list')

这很奇怪,因为应用迁移时出现这个错误这个早期工作正常,并且在这个步骤中的南方进程点, deleted_at 不应该也不存在于我的数据库中。我发现使用加载夹具移动迁移从步骤0004之后的0009解决问题,但它看起来像非常脏和不好的方法来解决这个问题。



你有什么建议如何解决这个问题妥善处理南方的迁移和装载工具?

解决方案

我找到了解决问题的办法。最后,我从南移植中提取了装载装置,并将此操作委托给Fabric。现在我分离了迁移并加载初始数据,所以一切都按照我的预期工作。


I've Django project which is using South application to handle schema and data migration. In one of my applications I have migration (number 0004) which is responsible for loading data fixtures from json file:

class Migration(DataMigration):

    def forwards(self, orm):
        from django.core.management import call_command
        call_command("loaddata", "dummy_data.json")

In the same project I try to add functionality of 'soft delete' which needs adding one more filed, defined as:

deleted_at = models.DateTimeField(blank=True, null=True)

Based on this change I've added new migration, which has number 0009. After that I start migrate command which give me error:

DatabaseError: Problem installing fixture 'C:/Users/Grzegorz/PycharmProjects/Dummy Project/Dummy\app_subapp\fixtures\dummy_data.json': Could not load app_subapp.DummyData(pk=1): (1054, "Unknown column 'deleted_at' in 'field list'")

It's quite strange, because this error occurs while applying migration 0004 which earlier worked ok and from point of South process in this step filed deleted_at shouldn't and doesn't exists in my database.I've found that moving migration with loading fixture from step 0004 after 0009 resolves problem, but it looks like very dirty and not good approach to resolve this issue.

Do you have any advices how can I resolve this problem and properly handle migrations and fixture loading with South?

解决方案

I've found workaround to my problem. Finally I've extracted load fixtures from South migration and delegated this action to Fabric. Now I have separated migration and load initial data, so everything works as I expect.

这篇关于在Django项目中无法使用South加载固定装置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆