0

所以我正在尝试进行数据迁移,将房地产应用程序中的“列表”放入我创建的新“列表”应用程序中。

我做了这样的开始迁移:

python manage.py startmigration listings migrate_listings --freeze realestate

创建了一个空白迁移,我填充了这个:

def forwards(self, orm):
        "Write your forwards migration here"
        for listing in orm['realestate.RealEstateListing'].objects.all():
            sub_type = orm.SubType.objects.get(slug_url=slugify(listing.listing_type.name))
            lt = orm.Listing(listing_type=sub_type.parent,
                             sub_type=sub_type,
                             expiration_date=listing.expiration_date,
                             title=listing.title,
                             slug_url = listing.slug_url,
                             description = listing.description,
                             contact_person=listing.contact_person,
                             secondary_contact=listing.secondary_contact,
                             address=listing.address,
                             location=listing.location,
                             price=listing.price,
                             pricing_option=listing.pricing_option,
                             display_picture=listing.display_picture,
                             image_gallery=listing.image_gallery,
                             date_added=listing.date_added,
                             status=listing.status,
                             featured_on_homepage=listing.featured_on_homepage,
                             )
            lt.save()

            lt.features.clear()
            for ft in listing.property_features.all:
                lt.features.add(ft)

            for cft in listing.community_features.all:
                lt.features.add(cft)

            lt.restrictions.clear()    
            for na in listing.not_allowed.all:
                lt.restrictions.add(na)

但是,当我运行迁移时仍然出现此错误:

whiney_method

ValueError("你不能实例化存根模型")

据我了解,您无法使用 fakeorm 访问“存根”模型,但不允许冻结其他应用程序。我如何在不冻结它们的情况下使用“存根”模型?

4

1 回答 1

2

好的,所以我正在回答我自己的问题,因为显然我是这里唯一的 django south 用户。我必须自己弄清楚。

我没有做的是冻结上述迁移中所需的所有应用程序。因为我没有冻结它创建了存根模型。

冻结多个应用程序的正确语法是:

python manage.py startmigration listings migrate_listings --freeze realestate --freeze logistics --freeze media --freeze upload

之后一切正常!

于 2009-06-25T06:34:11.000 回答