我正在尝试在数据迁移期间创建新对象。据我所知,我应该使用orm.Object()
来创建新对象,但这似乎不起作用:
def forwards(self, orm):
for o in orm['app.Objects'].objects.all():
...
n = orm.NewObject()
n.date = datetime.date.today()
n.object = o
n.save()
我收到错误
AttributeError: 'NoneType' object has no attribute 'date'
当我运行迁移时,建议未正确创建n
。我做错了什么?
答案 0 :(得分:1)
我通常将它们创建为:
def forwards(self, orm):
for obj in orm['my_app.ModelName'].objects.all():
orm.SomeOtherModel.objects.create(some_property=obj.some_property)