什么是Django 1.7+相当于South的add_ignored_fields()? [英] What's the Django 1.7+ equivalent to South's add_ignored_fields()?

查看:150
本文介绍了什么是Django 1.7+相当于South的add_ignored_fields()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以前的Django版本中,我们都使用了South进行迁移,而且由于它不像我们所希望的那样聪明,所以有时我们需要明确地忽略某些字段,因为这样的字段太复杂了它来处理。我们用 add_ignored_fields 这样做,一切都很有效。



在我们的例子中,我们有一个field我们的模型是 CharField 的子类,实际上通过 contribut_to_class 方法将两个附加字段附加到模型中。这是一个奇怪的过程,但它对我们的用例是有道理的,并且工作得很好,直到我们升级到Django 1.7。



然而,随着新的迁移系统,我们使用 add_ignored_fields()不再适用,我们的单元测试正在爆炸,因为它尝试使用这些字段创建测试数据库表。具体来说:

  django.db.utils.OperationalError:重复列名称:our_column_name 

在这种情况下, our_column_name 是此特殊CharField子类创建的字段之一。 p>

在一个完美的世界中,我们可以让迁移代码正确处理这些字段,但是我会为1.7版本的 add_ignored_fields()如果它存在。



我还应该指出,我们发现 Django文档中解构 的解释,但我害怕对我没有任何意义。我不知道是否适用于这种情况。

解决方案

我们发现这个Django票几乎说明这是一个设计模式,开发者不支持,所以我们只是去必须重写模型以明确创建模型上的其他字段,然后从父字段中引用所述字段a la ImageField


Back in previous versions of Django, we all used South to do migrations, and because it wasn't as smart as we might have liked, we sometimes needed to tell it to explicitly ignore some fields because such fields were too complicated for it to handle. We did this with add_ignored_fields and everything pretty much worked.

In our case, we have a "field" on our model that's a subclass of CharField that actually attaches two additional fields to the model via the contribute_to_class method. It's kind of a weird process, but it makes sense for our use case and worked just fine until we upgraded to Django 1.7.

However, with the new migrations system, our use of add_ignored_fields() no longer works and our unit tests are exploding as it tries to create a test database table with these fields. Specifically it says:

django.db.utils.OperationalError: duplicate column name: our_column_name

In this case our_column_name is one of the fields this special CharField subclass creates.

In a perfect world, we could have the migration code handle these fields properly, but I'd settle for the 1.7 version of add_ignored_fields() if it exists.

I should also point out that we've found the explanation for deconstruct in the Django documentation, but I'm afraid that it doesn't make any sense to me. I can't figure out if it applies to this situation or not.

解决方案

We've discovered this Django ticket that pretty much states that this is a design pattern that the devs aren't supporting, so we're just going to have to rewrite the model to explicitly create the other fields on the model and then reference said fields from the "parent" field a la ImageField.

这篇关于什么是Django 1.7+相当于South的add_ignored_fields()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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