0
我試圖從舊的MySQL數據庫到新的Django的通訊應用程序導入新聞訂閱,代碼如下:Django中添加用戶時,如外鍵得到django.utils.functional .__ proxy__例外
for _ns in CmsModuleNmsList.objects.using('old').all():
ns = Newsletter(pk=_ns.listid, title=_ns.name, slug=slugify(_ns.name), email='[email protected]', sender='Admin')
ns.save()
for _list in CmsModuleNmsListuser.objects.using('old').filter(listid=_ns.listid):
try:
_user = CmsModuleNmsUsers.objects.using('old').get(userid=_list.userid)
user = None
try:
user = User.objects.get(email=_user.email)
except:
print "Cannot find user"
Subscription(newsletter=ns, user=user, subscribed=True, email_field=_user.email, name_field=_user.username, create_date=_user.dateadded).save()
except Exception as e:
transaction.rollback()
print _user.username, 'Error', str(e)
當我運行它,我得到這樣的異常,由此線Subscription(newsletter=ns, user=user, subscribed=True, email_field=_user.email, name_field=_user.username, create_date=_user.dateadded).save()
,如果我拿出user=user
我沒有得到例外。