Opened 7 years ago

Closed 6 years ago

Last modified 6 years ago

#18085 closed Bug (worksforme)

sqllite integer is signed but django recognize as unsigned

Reported by: robotr Owned by: nobody
Component: Documentation Version: 1.4
Severity: Normal Keywords: tutorial
Cc: m.r.sopacua@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


When making "Writing your first Django app, part 2", I recieve this below:

IntegrityError at /admin/

column username is not unique

Request Method: 	POST
Request URL:
Django Version: 	1.4
Exception Type: 	IntegrityError
Exception Value: 	

column username is not unique

Exception Location: 	D:\Python2.7.3\lib\site-packages\django\db\backends\sqlite3\ in execute, line 337
Python Executable: 	D:\Python2.7.3\python.exe
Python Version: 	2.7.3
Python Path: 	


Server time: 	Sun, 8 Apr 2012 23:12:11 +0800

the superuser id is "1", but as django said is "4294967296"
my superuser can not login.

Change History (4)

comment:1 Changed 7 years ago by Florian Apolloner

Resolution: needsinfo
Status: newclosed

Hi, can you provide more info? Especially a traceback would be helpful

comment:2 Changed 6 years ago by vincent.desprez@…

Resolution: needsinfo
Status: closedreopened
Type: UncategorizedBug

Hello, same error. Here is my traceback.


Request Method: POST
Request URL:

Django Version: 1.4.1
Python Version: 2.7.3
Installed Applications:
Installed Middleware:

File "C:\Python27\lib\site-packages\django\core\handlers\" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "C:\Python27\lib\site-packages\django\contrib\admin\" in wrapper
  213.                 return self.admin_view(view, cacheable)(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\utils\" in _wrapped_view
  91.                     response = view_func(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\views\decorators\" in _wrapped_view_func
  89.         response = view_func(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\contrib\admin\" in inner
  195.                 return self.login(request)
File "C:\Python27\lib\site-packages\django\views\decorators\" in _wrapped_view_func
  89.         response = view_func(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\contrib\admin\" in login
  326.         return login(request, **defaults)
File "C:\Python27\lib\site-packages\django\views\decorators\" in sensitive_post_parameters_wrapper
  69.             return view(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\utils\" in _wrapped_view
  91.                     response = view_func(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\views\decorators\" in _wrapped_view_func
  89.         response = view_func(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\contrib\auth\" in login
  49.             auth_login(request, form.get_user())
File "C:\Python27\lib\site-packages\django\contrib\auth\" in login
  76.     user_logged_in.send(sender=user.__class__, request=request, user=user)
File "C:\Python27\lib\site-packages\django\dispatch\" in send
  172.             response = receiver(signal=self, sender=sender, **named)
File "C:\Python27\lib\site-packages\django\contrib\auth\" in update_last_login
File "C:\Python27\lib\site-packages\django\db\models\" in save
  463.         self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "C:\Python27\lib\site-packages\django\db\models\" in save_base
  551.                 result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
File "C:\Python27\lib\site-packages\django\db\models\" in _insert
  203.         return insert_query(self.model, objs, fields, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\" in insert_query
  1576.     return query.get_compiler(using=using).execute_sql(return_id)
File "C:\Python27\lib\site-packages\django\db\models\sql\" in execute_sql
  910.             cursor.execute(sql, params)
File "C:\Python27\lib\site-packages\django\db\backends\" in execute
  40.             return self.cursor.execute(sql, params)
File "C:\Python27\lib\site-packages\django\db\backends\sqlite3\" in execute
  337.             return Database.Cursor.execute(self, query, params)

Exception Type: IntegrityError at /admin/
Exception Value: column username is not unique


comment:3 Changed 6 years ago by Melvyn Sopacua

Cc: m.r.sopacua@… added
Component: UncategorizedDocumentation
Keywords: tutorial added
Resolution: worksforme
Status: reopenedclosed

I don't see how the traceback relates to your bug description. The SQL error points to the username field, which is a character field and your bug report mentions signed/unsigned issues with a numeric field. Many of us have gone through the tutorial without issues so try to figure out what you have done differently or at the very least explain how you came to the conclusion that above traceback is caused by a signedness issue.

comment:4 Changed 6 years ago by Karen Tracey

That's a very puzzling traceback. What it shows happening is Django auth code logging a user in (auth_login(request, form.get_user())), which causes the user logged in signal to fire (user_logged_in.send(sender=user.__class__, request=request, user=user)), which has a receiver in the auth models file (update_last_login) that sets the user's last login time to now and saves the user. Now things start to get weird. The Django ORM level code, instead of taking the path of saving an existing User model instance, takes the path of inserting a new row into the auth_user table. This path would ordinarily only be taken if the User instance primary key value was not set, but it must be set since the User model was retrieved from the DB earlier, and would not have been cleared by anything shown as installed in the system (full traceback is showing only Django code installed). At any rate this "new" user has an identical username to an existing user (likely the one logging in!) so the DB raises an integrity error.

This is two people now reporting this exception on what looks to be some version of Windows, Django 1.4.1, and Python 2.7.3. However I cannot recreate it on my Windows7/Django1.4.1/Python2.7.3 machine. The original report mentions 'the superuser id is "1", but as django said is "4294967296" my superuser can not login' but does not give any details of where that 42.. number was seen. It is a special number:

>>> hex(4294967296)

1 in the high 32-bits of a 64-bit number, 0 in the low 32 bits, but how a 1 would get to be stored that way isn't clear to me. My best guess is there is some 32-bit vs. 64-bit incompatibility in the underlying Python/sqlite libraries installed. FWIW in my working setup I've got 64-bit Python installed on 64-bit Windows.

Note: See TracTickets for help on using tickets.
Back to Top