3

I am trying to add new user with admin interface and get this error:

IntegrityError at /admin/main/customuser/add/

������������: INSERT ������ UPDATE �� �������������� "django_admin_log" ���������������� ���������������������� ���������������� ���������� "django_admin_log_user_id_fkey" DETAIL: �������� (user_id)=(1) ���������������������� �� �������������� "auth_user".

Here is traceback:

 File "C:\Python33\lib\site-packages\django\core\handlers\base.py", line 115, in get_response
 response = callback(request, *callback_args, **callback_kwargs)
 File "C:\Python33\lib\site-packages\django\contrib\admin\options.py", line 372, in wrapper
 return self.admin_site.admin_view(view)(*args, **kwargs)
 File "C:\Python33\lib\site-packages\django\utils\decorators.py", line 91, in _wrapped_view
 response = view_func(request, *args, **kwargs)
 File "C:\Python33\lib\site-packages\django\views\decorators\cache.py", line 89, in _wrapped_view_func
 response = view_func(request, *args, **kwargs)
 File "C:\Python33\lib\site-packages\django\contrib\admin\sites.py", line 202, in inner
 return view(request, *args, **kwargs)
 File "C:\Python33\lib\site-packages\django\utils\decorators.py", line 25, in _wrapper
 return bound_func(*args, **kwargs)
 File "C:\Python33\lib\site-packages\django\utils\decorators.py", line 91, in _wrapped_view
 response = view_func(request, *args, **kwargs)
 File "C:\Python33\lib\site-packages\django\utils\decorators.py", line 21, in bound_func
 return func(self, *args2, **kwargs2)
 File "C:\Python33\lib\site-packages\django\db\transaction.py", line 223, in inner
 return func(*args, **kwargs)
 File "C:\Python33\lib\site-packages\django\db\transaction.py", line 217, in __exit__
 self.exiting(exc_value, self.using)
 File "C:\Python33\lib\site-packages\django\db\transaction.py", line 281, in exiting
 commit(using=using)
 File "C:\Python33\lib\site-packages\django\db\transaction.py", line 152, in commit
 connection.commit()
 File "C:\Python33\lib\site-packages\django\db\backends\__init__.py", line 241, in commit
 self._commit()
 File "C:\Python33\lib\site-packages\django\db\backends\postgresql_psycopg2\base.py", line 242, in _commit
 six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2])
 File "C:\Python33\lib\site-packages\django\utils\six.py", line 328, in reraise
 raise value.with_traceback(tb)
 File "C:\Python33\lib\site-packages\django\db\backends\postgresql_psycopg2\base.py", line 240, in _commit
 return self.connection.commit()

I am using Postgres with psycopg2 and cant understand where is problem. On django side, on Postgres or may be in psycopg2?

Also when I am logging to admin again, it was responsde that user have been added successfully, but there is no new users in database table.

Michael
16.3k39 gold badges100 silver badges146 bronze badges
asked Jul 21, 2013 at 13:48
1
  • May be it wiil help, but if i run syncdb command on blank database, it doesnt create 2 tables: auth_users and auth_user_groups. Commented Jul 21, 2013 at 14:56

1 Answer 1

1

I haven't solve problem with encoding in database response, but i've solved problem in general. I added custom auth backend and no more error messages from database. Here my example backend that solve the problem:

class CustomBackend (ModelBackend):
 def authenticate(self, username=None, password=None, **kwargs):
 if kwargs:
 try:
 user = CustomUser.objects.get(id = kwargs['id'])
 except CustomUser.DoesNotExist:
 #print ("WE ARE HERE!", kwargs)
 user = CustomUser(nickName=kwargs['nickName'], id=kwargs['id'])
 user.reputation = 0
 user.save()
 return user
 if username == 'admin' and password == 'admin':
 return CustomUser.objects.get(nickName='m9')
 def get_user(self, user_id):
 try:
 return CustomUser.objects.get(id=user_id)
 except CustomUser.DoesNotExist:
 return None
answered Jul 22, 2013 at 19:31
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.