如果不创建新条目,如果条目已经存在,我正在尝试更新数据库。
def saveprofile(request):
location = request.POST['location']
email = request.POST['email']
if request.user.is_authenticated():
userprofile = UserProfiles(user=request.user)
if userprofile:
userprofile.location=location
userprofile.email=email
userprofile.save()
return render_to_response('profile.html',{'pfields':userprofile})
else:
userprofile = UserProfiles(user=request.user, location=location, email=email)
userprofile.save()
return render_to_response('profile.html',{'pfields':userprofile})
它在扔
(1062,“密钥‘user_id’的重复条目‘15’”)