我正在使用 South 进行 sqlite3 数据迁移。我的旧架构具有以下 UserProfile 模型:
class UserProfile(models.Model):
user = models.OneToOneField(User)
weekOne = models.OneToOneField(WeekOne)
weekTwo = models.OneToOneField(WeekTwo)
weekThree = models.OneToOneField(WeekThree)
但我感觉添加了一些新的周,即 weekFour、weekFive、weekSix 等。每周本身就是一个模型,继承自一个通用的 Week 模型。所以 Week 模型的基本原型如下所示:
class WeekOne(Week):
name = u'Week One'
exercises = ['squats', 'lunges', 'stairDaysCount', 'skipStairs']
# Required benchmarks for given exercises
squatBenchmark = 1000
lungeBenchmark = 250
stairDaysCountBenchmark = 3
totalGoals = 4
我的问题是,我应该在我的数据迁移代码中放入什么样的代码,以便我可以UserProfile
用额外的几周填充旧的 s。我有这样的想法:
def forwards(self, orm):
for user in orm.UserProfile.objects.all():
user.weekFour = orm.WeekFour()
user.weekFive = orm.weekFive()
# etc.
但这似乎不起作用。当我尝试运行架构迁移时出现此错误:
Migration 'my_app:0002_newWeeks' is marked for no-dry-run
后来这个:
DatabaseError: no such column: my_app_userprofile.weekFour_id