Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 924747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:24:34+00:00 2026-05-15T19:24:34+00:00

I have modified my application, so that when a new user is registered, it’s

  • 0

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 ‘my@email.com’ 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 'my@email.com' 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)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T19:24:34+00:00Added an answer on May 15, 2026 at 7:24 pm

    I’d catch MySQLdb error in this init file of registration backend, since it is first to cause problems :

    import MySQLdb

    (...)
        new_user = None
        try:    
            new_user = RegistrationProfile.objects.create_inactive_user(username, email, password, site)
        except MySQLdb.IntegrityError:
            pass
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.