django South ValueError:“您无法实例化存根模型”

发布于 2024-07-26 02:45:34 字数 2067 浏览 2 评论 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)

但是当我运行迁移时仍然收到此错误:

whey_method

ValueError(“你无法实例化存根模型”)

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

so i'm trying to do a data migration where i take the "listings" from a realestate app into a new "listings" app that i've created.

i did startmigration like this:

python manage.py startmigration listings migrate_listings --freeze realestate

created a blank migration, which i populated with this:

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)

however when i run the migration is still get this error:

whiney_method

ValueError("you cannot instantiate a stub model")

from what i understand you can't access a "stub" model using the fakeorm but freezing additional apps is not allowed. how do i go about using the "stub" models without freezing them?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

疧_╮線 2024-08-02 02:45:34

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

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

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

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

之后一切正常!

ok so i'm answering my own question, since apparantly i'm the only django south user here. i had to figure it out by myself.

what i wasn't doing, was freezing all the apps that were required in the above migration. since i didn't freeze it created the stub models.

the proper syntax for freezing multiple apps is:

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

and everything works after that!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文