django-allauth + django-invitations: IntegrityError at /accounts/signup/, duplicate username - django

I am using django-allauth + django-invitations. When I access the url in the emailed invitation sent from django-invitations, I receive this error.
IntegrityError at /accounts/signup/
duplicate key value violates unique constraint "accounts_userplus_username_key"
DETAIL: Key (username)=() already exists.
Request Method: POST
Request URL: http://127.0.0.1:8000/accounts/signup/
Django Version: 4.0.5
Exception Type: IntegrityError
Exception Value:
duplicate key value violates unique constraint "accounts_userplus_username_key"
DETAIL: Key (username)=() already exists.
UserPlus is my custom model name

I had ACCOUNT_USER_MODEL_USERNAME_FIELD = None in my settings.py file. Removing this resolves the error - an empty username (I think)

Related

Django-Rest-Framework 3.0 ImproperlyConfigured at /api/users/ Field name `is_owner` is not valid for model `User`

Have some strange bug in my project. I was remove is_owner field from user's model, made migrations and now when i'm sending post request to my user's endpoint i have this exception.
django.core.exceptions.ImproperlyConfigured: Field name is_owner is not valid for model User.
But i can't found any place in project, using Ctrl Shift F, where old i_owner field still can be called. In ruquest i using this field nowhere too.
Request

Django User model with encrypted and hashed email as username

I have a custom User model with email as username.
I have encrypted the email field to be in conformity with GPDR (I will hold a lot of personal information).
I have added a email_hash field with index on it for the database to be able to retrieve immediately user.
I have modified get_natural_key of my user object manager to use the hash for retrieve.
But now i face a problem I have to disable the uniqueness on field email (username field) but Django don't let me do it when i try to makemigrations.
myuser.MyUser: (auth.E003) 'MyUser.email' must be unique because it is named as the 'USERNAME_FIELD'.
Otherwise, I want the uniqueness error to be fired on email field and not on email_hash field ....
How to have functional encrypted email field as user and stored hash for index ?
edit:
I have disable uniqueness check on email field and added SILENCED_SYSTEM_CHECKS = ["auth.E003"] in settings.
Now my problem is to have uniqueness error of email_hash rendered as email error to have "A user with that email address already exists." message displayed on correct forms and django rest framework serializer field.

rest_framework.authtoken app migration error

I am not able to install rest_framework.authtoken app in custom User model.
The User model table is assigned name users with db_table=u'user'. While running migration of rest_framework.authtoken gives error
Running migrations for authtoken:
- Migrating forwards to 0001_initial.
authtoken:0001_initial
FATAL ERROR - The following SQL query failed: ALTER TABLE "authtoken_token" ADD CONSTRAINT "user_id_refs_id_14b35167" FOREIGN KEY ("user_id") REFERENCES "users_user" ("id") DEFERRABLE INITIALLY DEFERRED;
The error was: relation "users_user" does not exist
Error in migration: authtoken:0001_initial
DatabaseError: relation "users_user" does not exist
setting have been configured in setting.py with AUTH_USER_Model="users.User". The table in database exist with name user.But, still i am receiving error. Can somebody point out my error. Thank you.

Zinnia Blog doesn't use custom auth user model

I am using Zinnia Blog module with my Django app. I have a Django app and have a custom User model. I have added the following setting:
AUTH_USER_MODEL = 'account.Member'
However, when I try to create a new entry in the blog I get the Foreign Key constraint error.
Exception Type: IntegrityError
Exception Value:
(1452, 'Cannot add or update a child row: a foreign key constraint fails (`example`.`zinnia_entry_authors`, CONSTRAINT `author_id_refs_id_410656e2874b02ff` FOREIGN KEY (`author_id`) REFERENCES `auth_user` (`id`))')
It references the default auth model (which doesn't exist in the database) instead of the specified auth model. How do make Zinnia use the correct table.
Thanks.

Issues with auth_user table in django

I want to update some fields of auth_user table in django. Actually i am migrating some users from one website to another so i want to update the password field in auth_user table.But when i am using the update query it gives me some errors
some things which i have tried
values=User.objects.get(username=request.POST['username'])
values.password=request.POST['password']
values.password.save()
it gives the error of 'unicode' object has no attribute 'save
and if i tried this one
values=User.objects.get(username=request.POST['username']).update(password=request.POST['password'])
then the error is 'User' object has no attribute 'update'
actually i do not want to send emails to users to update their password and redirect them to forgot password page.
But whenever user try to login to site and if his password do not match but he typed the password correctly but due to migration his password do not work in django then the password he enters must be updated in auth_user table(encrypted password).
In between i have ensure that this user is the authenticate user of previous site.
So please suggest me some way so that i can update his password in auth_user table.
Passwords in django are stored as sha256 hashes, so setting
user.password = 'new password'
is not a good idea. Fortunately django has methods that would take care of hashing your password. Second thing:
values.password.save()
Here you are trying to execute save() method on password object which is a string, not a user object. values.save() would be better, but still not correct. What you want to do is this:
values.set_password('new password') # Takes care of hashing
values.save()
More on the topic in django documentation
(On behalf of OP)
I used this and the problem is solved
u = User.objects.get(username__exact='john')
u.set_password('new password')
u.save()