开发者

Django South data migration is running twice

开发者 https://www.devze.com 2022-12-21 13:41 出处:网络
I have a migration: ... def forwards(self, orm): for p in products.models.Product.objects.all(): new = cart.models.Product(title =开发者_运维问答 p.title)

I have a migration:

    ...

def forwards(self, orm):
    for p in products.models.Product.objects.all():
        new = cart.models.Product(title =开发者_运维问答 p.title)
        new.save()

    def backwards():
        ...

But when I run migrate it runs through the loop twice.


do you have

no_dry_run = True

in the migration definition?

besides, I think you should be using orm.Product.objects.all()


This happens because South run twice: first time it not touch DB, second time push changes to db.

Fast solution run ./manage migrate your_app --db-dry-run

Or use

if not db.dry_run:

in your code in forward/backward sections

discussed here http://south.aeracode.org/ticket/138

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号