Opened 8 years ago
Closed 7 weeks ago
#27909 closed Cleanup/optimization (wontfix)
Use AUTH_USER_MODEL in startproject template
Reported by: | David D Lowe | Owned by: | nobody |
---|---|---|---|
Component: | Core (Management commands) | Version: | 1.10 |
Severity: | Normal | Keywords: | |
Cc: | Carsten Fuchs, Tom Carrick | Triage Stage: | Someday/Maybe |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The documentation says:
If you’re starting a new project, it’s highly recommended to set up a custom user model, even if the default User model is sufficient for you. This model behaves identically to the default user model, but you’ll be able to customize it in the future if the need arises:
If you fail to remember to do this when you set up the project, the documentation warns of the difficulty of doing it later:
Changing AUTH_USER_MODEL after you’ve created database tables is significantly more difficult since it affects foreign keys and many-to-many relationships, for example.
This change can’t be done automatically and requires manually fixing your schema, moving your data from the old user table, and possibly manually reapplying some migrations. See #25313 for an outline of the steps.
And it continues, explaining the other difficulties and caveats.
Starting your project with AUTH_USER_MODEL set is highly recommended, and it is a difficult to switch to this method once a project has been created. So why doesn't the default template created by django-admin startproject
give a value to AUTH_USER_MODEL
by default?
Change History (8)
comment:1 by , 8 years ago
Component: | Uncategorized → Core (Management commands) |
---|---|
Summary: | Use AUTH_USER_MODEL in quick-start template → Use AUTH_USER_MODEL in startproject template |
Triage Stage: | Unreviewed → Someday/Maybe |
Type: | Uncategorized → Cleanup/optimization |
comment:2 by , 6 years ago
Since you need a model to hand to AUTH_USER_MODEL, and this model should be in an app, you can't really populate this setting in startproject
, before having run startapp
. Adding an app directly on startproject
seems like taking the defaults too far, at least to me, so I'm not clear on where this value for AUTH_USER_MODEL is supposed to come in.
comment:3 by , 6 years ago
I guess the underlying issue is that it is so hard to migrate from not having AUTH_USER_MODEL set to having it set. If it were easier to migrate, then it wouldn't matter what it was set to in the startproject template.
comment:4 by , 3 years ago
I've issued a PR that does this and makes the configuration directory named config
instead of {{ project_name }}
here: https://github.com/django/django/pull/15609
These two items have been the most frequent pain points I've run into when teaching newcomers.
comment:5 by , 21 months ago
Cc: | added |
---|
comment:6 by , 13 months ago
👋 reading this ticket, and https://forum.djangoproject.com/t/django-new-project-structure-name/9987/10, and https://groups.google.com/g/django-developers/c/SwFAy8GbhmE – it seems to me like this is only blocked by the decision on the project structure. Other than that blocker, I see lots of approval for:
- A custom user model by default
- It being in a
users
app - And there’s been no feedback on Tim’s PR to name said model
User
in amodels.py
file (phew).
I thought I’d record this here to note at least what there seems to be consensus on.
comment:7 by , 12 months ago
Cc: | added |
---|
comment:8 by , 7 weeks ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
This seems obsolete as of #35767, since it's no longer recommended to start a project with a custom user model.
This was proposed in ticket:24370#comment:3, however, it should be discussed on the DevelopersMailingList to ensure there's consensus about it. Feel free to start a thread.