django South ValueError:“您无法实例化存根模型”
所以我正在尝试进行数据迁移,将房地产应用程序中的“列表”放入我创建的新“列表”应用程序中。
我是这样开始迁移的:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我正在回答我自己的问题,因为显然我是这里唯一的 django South 用户。 我必须自己弄清楚。
我没有做的是冻结上述迁移中所需的所有应用程序。 因为我没有冻结它创建的存根模型。
冻结多个应用程序的正确语法是:
之后一切正常!
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:
and everything works after that!