我正在使用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等。每周本身就是一个模型,继承自通用周模型。因此,周模型的基本原型如下所示:
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
。我有类似的想法:
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
答案 0 :(得分:0)
只需在终端中运行
python manage.py schemamigration myapp --auto
然后
python manage.py migrate