Reputation: 3554
Hi i am getting the duplicate entry when i am running this code but cant sure why it is happening Below is the code
def match_domain(request):
user_domain_array = ['[email protected]','[email protected]','[email protected]']
getclientdomain = client_domain.objects.all()
for i in getclientdomain:
for u in user_domain_array :
if i.client_domain in u :
saveuser = User(email = u)
saveuser.save()
#return HttpResponse(u)
else :
return HttpResponse("no")
getclientdomain has one entry in database with the value of ghrix.com , it inserts the first element from the array to database and after that throwing the duplicate entry error please suggest me where i am doing a mistake .
Upvotes: 0
Views: 831
Reputation: 1736
You can try this : Send something different every-time for username field too , because looking at your save query , you only insert email So I think username field must be blank . So first time it insert the first row but 2nd time it doesn't insert and gives the duplicate entry error.
Upvotes: 1