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
精彩评论