我想使用South 将字段的鸣喇叭和数据从一个模型移动到另一个模型:
class Foo(models.Model):
foofield = models.CharField()
honk = models.PositiveIntegerField()
class Bar(models.Model):
barfield = models.CharField()
Run Code Online (Sandbox Code Playgroud)
我以前做过这个,使用3次单独的迁移:
我已经了解到南方的模式和数据迁移之间没有太大差别,所以我想也许这样的东西可能会起作用(这就是上面的三个迁移只是一个):
class Migration(DataMigration):
def forwards(self, orm):
# add column
db.add_column('myapp_bar', 'honk', self.gf('django.db.models.fields.PositiveIntegerField')(default='0'), keep_default=False)
# copy data
for foo in Foo.objects.all():
# find the right bar here and then ...
bar.honk = foo.honk
bar.save()
# remove old column
db.delete_column('myapp_foo', 'honk')
Run Code Online (Sandbox Code Playgroud)
这会起作用还是会失败,因为我(南方冻结)的orm还不知道Bar.honk呢?或者我做错了,在一次迁移中有更好的方法来做这种事情吗?
django-south ×1