我正在编写一个小数据迁移,为没有UserProfiles的现有Django用户创建UserProfiles。在
def forwards(self, orm):
"Write your forwards methods here."
for user in User.objects.all():
try:
person = user.get_profile()
except:
newperson = orm.Person(user=user)
newperson.save()
但我总是
^{pr2}$
我做错什么了?在
Tags:
在South编写迁移时,不必直接使用models类,而是使用冻结的类。在上面的例子中,您可能试图将当前的用户对象分配给冻结的个人对象。冻结的人对象需要冻结的用户对象。在
您需要重写如下:
见http://south.readthedocs.org/en/latest/ormfreezing.html#accessing-the-orm
顺便说一句,我建议你不要使用一个“除了”之外的“裸”,而是“”,除非有一些异常,这样更健壮。在
相关问题 更多 >
编程相关推荐