Reputation: 20856
I have a user in my django table - auth_user. The username = 'django' but when I check the id its None.
When I check in the tables, the id is set to 1.
Not sure why u.id is None.
Upvotes: 0
Views: 998
Reputation: 10588
The following code creates a user object but does not save it to the database:
# here u.id is None
u = User(username="django")
An id is associated to a new user object whenever it is added to the database:
# here u.id is not None
u = User.objects.create(username="django")
If the user object already exists, then it can be loaded from the database and the id
attribute will be properly defined:
u = User.objects.get(username="django")
Upvotes: 3