Inherited a Django app running production that hasn’t been touched since 2020 (Django 2.2 + outdated dependencies, PosgreSQL 10.2), so I took the codebase, updated everything, and the only part of the code I touched was
settings.py. Managed to make it run, logged in with a dummy account added via
manage.py createsuperuser, and everything works.
At this point, I decided to do a
pg_dump in production, replayed it on the dev side, (partially) applied the migrations, served it, and then tried to log in with my user that I use on the production version, but I get the following error:
django.contrib.auth.models.User.account.RelatedObjectDoesNotExist: User has no account.
I figured out that my user in the
auth_user table has no corresponding entry in the
account_account table using the SQL statement below:
SELECT * FROM account_account AS a JOIN auth_user AS u ON a.user_id = u.id;
The problem is that this is true for the app running in production as well and yet it still works. Now, I was able to get it to work by simply adding a corresponding entry to
SELECT id FROM auth_user WHERE username = 'my_username'; --> 27 INSERT INTO account_account(id, timezone, language, user_id) VALUES (107,'','en', 27);
but even though we don’t have many users, this won’t be fun to do with each of them. (Um, should I just repeat this with every user? Should this be a migration? ) Anyway, at this point I’m just curious where (i.e., which version) this change in behaviour was introduced.
(I’m learning SQL, PostgreSQL, Python, and Django together on this “mission”, and had quite a ride so far even just getting things up to date. Nonetheless, I have tremendous respect for all of you making this framework so user friendly and the documentation is great. Thank you!)