I have modified my application, so that when a new user is registered, it's username and email are the same. But when a new user is created, I'm getting IntegrityError : (1062, "Duplicate entry '[email protected]' for key 'username'"), still the user is created correctly.
Function register_new in which a new user is created ('temp_data' is a dict from form.cleaned_data) :
def register_new(request):
data = request.session['temp_data']
email = data['email']
password1 = data['password1']
userdata = {'email': email, 'password1': password1}
backend = request.session['backend']
user = backend.register(request, userdata)
,here's the registration.backend register function, that creates new user :
def register(self, request, userdata):
logging.debug("backend.register")
logging.debug(userdata)
username, email, password = userdata['email'], userdata['email'], userdata['password1']
if Site._meta.installed:
site = Site.objects.get_current()
else:
site = RequestSite(request)
new_user = RegistrationProfile.objects.create_inactive_user(username, email, password, site)
return new_user
Traceback :
File "/home/rails/site-packages/django/core/handlers/base.py" in get_response
92. response = callback(request, *callback_args, **callback_kwargs)
File "/home/rails//registration/views.py" in register_new
112. user = backend.register(request, userdata)
File "/home/rails/registration/backends/default/__init__.py" in register
21. password, site)
File "/home/rails/site-packages/django/db/transaction.py" in _commit_on_success
240. res = func(*args, **kw)
File "/home/rails/registration/models.py" in create_inactive_user
73. new_user = User.objects.create_user(username, email, password)
File "/home/rails/site-packages/django/contrib/auth/models.py" in create_user
105. user.save()
File "/home/rails/site-packages/django/db/models/base.py" in save
410. self.save_base(force_insert=force_insert, force_update=force_update)
File "/home/rails/site-packages/django/db/models/base.py" in save_base
495. result = manager._insert(values, return_id=update_pk)
File "/home/rails/site-packages/django/db/models/manager.py" in _insert
177. return insert_query(self.model, values, **kwargs)
File "/home/rails/site-packages/django/db/models/query.py" in insert_query
1087. return query.execute_sql(return_id)
File "/home/rails/site-packages/django/db/models/sql/subqueries.py" in execute_sql
320. cursor = super(InsertQuery, self).execute_sql(None)
File "/home/rails/site-packages/django/db/models/sql/query.py" in execute_sql
2369. cursor.execute(sql, params)
File "/home/rails/site-packages/django/db/backends/util.py" in execute
19. return self.cursor.execute(sql, params)
File "/home/rails/site-packages/django/db/backends/mysql/base.py" in execute
84. return self.cursor.execute(query, args)
File "build/bdist.linux-x86_64/egg/MySQLdb/cursors.py" in execute
173. self.errorhandler(self, exc, value)
File "build/bdist.linux-x86_64/egg/MySQLdb/connections.py" in defaulterrorhandler
36. raise errorclass, errorvalue
Exception Type: IntegrityError at /register_new/
Exception Value: (1062, "Duplicate entry '[email protected]' for key 'username'")
I've googled for solutions and found many different including deleting/syncing tables, catching the IntegrityError in different places, changing decoding fields for table columns (I've tried setting to utf8_bin but no results). How to fix this problem ?
Table structure :
http://i27.tinypic.com/dotmjs.png
http://i32.tinypic.com/1zq79tj.png
I've found this ticket at django docs : http://code.djangoproject.com/ticket/3083 But there should be 2 models created at the same time. In my case nothing like this takes place I guess :/
UPDATE Model :
class User(models.Model):
username = models.CharField(_('Email'), max_length=30, unique=True, help_text=_("Required. 30 characters or fewer."))
first_name = models.CharField(_('first name'), max_length=30, blank=True)
last_name = models.CharField(_('last name'), max_length=30, blank=True)
email = models.EmailField(_('e-mail address'), blank=True)
password = models.CharField(_('password'), max_length=128, help_text=_("Use '[algo]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>."))
is_staff = models.BooleanField(_('staff status'), default=False, help_text=_("Designates whether the user can log into this admin site."))
is_active = models.BooleanField(_('active'), default=True, help_text=_("Designates whether this user should be treated as active. Unselect this instead of deleting accounts."))
is_superuser = models.BooleanField(_('superuser status'), default=False, help_text=_("Designates that this user has all permissions without explicitly assigning them."))
last_login = models.DateTimeField(_('last login'), default=datetime.datetime.now)
date_joined = models.DateTimeField(_('date joined'), default=datetime.datetime.now)