Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 265
Cato Johnston Avatar asked Feb 26 '10 09:02

Cato Johnston


2 Answers

do you have

no_dry_run = True

in the migration definition?

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

like image 197
Ofri Raviv Avatar answered Nov 10 '22 03:11

Ofri Raviv


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

like image 5
b1_ Avatar answered Nov 10 '22 02:11

b1_