开发者

Django South data migration is running twice

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜