开发者

Does django auth supports the same user names?

开发者 https://www.devze.com 2023-03-27 17:43 出处:网络
I have two databases and i must move users infor fr开发者_运维知识库om these to django. The problem is that user names are repeated (these are other users). How does it solve?It doesn\'t \'solve\' mul

I have two databases and i must move users infor fr开发者_运维知识库om these to django. The problem is that user names are repeated (these are other users). How does it solve?


It doesn't 'solve' multiple user names - django.contrib.auth.models.User.username has unique=True so each one must be unique.

The database would solve that problem for you by spitting out a database IntegrityError when you try to add a second user with the same username.

If you have a working auth system with multiple usernames, then you're clearly not logging in with the username as a user's unique identifier.

Maybe you're using email addresses for login with the username field as just "flair" (almost like SO) - in which case I might modify the username field to be longer and store the email address in the username field / username in a user profile model.

https://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users

You could also potentially remove that unique constraint and write your own authentication backend that knows how to find your unique user / check its credentials. There must be /something/ unique about each user, right? https://docs.djangoproject.com/en/dev/topics/auth/#writing-an-authentication-backend

0

精彩评论

暂无评论...
验证码 换一张
取 消