Django first migration has one anonymous user
Django first migration has one anonymous user
When setting up a django project, the first time I run manage.py migrate
and go to manage.py shell
and run:
manage.py migrate
manage.py shell
from users.models import User
users = User.objects.all()
users
[<User: AnonymousUser>]
I always get this AnonymousUser
. After creating my superuser and checking on the admin page I get:
AnonymousUser
Does Django create this lonely AnonymousUser
for a specific purpose, or am I configuring something wrong?
AnonymousUser
2 Answers
2
I'm by no means an expert here but looking through the django auth docs, it seems as though django creates this user to handle apps where users can choose not to authenticate and still interact with app in some level.
If the current user has not logged in, this attribute [request.user] will be set to an instance of AnonymousUser, otherwise it will be an instance of User.
Is this what you were looking for?
I have this issue with django-guardian, this apps creates AnonymousUser in the first migrate.
The docs says:
GUARDIAN_GET_INIT_ANONYMOUS_USER
New in version 1.2.
Guardian supports object level permissions for anonymous users, however when in
our project we use custom User model, default function might fail. This can lead
to issues as guardian tries to create anonymous user after each syncdb call.
Object that is going to be created is retrieved using function pointed by this
setting. Once retrieved, save method would be called on that instance.
Defaults to "guardian.management.get_init_anonymous_user".
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Precisely, I haven't found the migration implementation on the source code, but it's a good surprise to see this in the documentation.
– sargas
Sep 6 '15 at 3:58