Custom userIt is always useful to create a custom user model even if the default one is also appropriate for you. As the documentation itself says, with the custom user model, you can do custom adjustments in the future. Well, in this section I am writing about an implementation of a custom user model. With this model, you will be able to manage your own user database and track user activities.


Models in Django are Python classes, and their attributes represent database fields. To utilize them, you need a database first of all. The default one is sqlite3, but later, and especially in the case of more complex data assets, you should use a production-ready, professional one. I am using Postgres. You can see here how to set up a Postgres db for this Django project.

You should create your custom user model before the very first migrate command! This could be tricky later.

Doing this is basically changing the AUTH_USER_MODEL for a custom one.

" 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. "

As the documentation states here.

$ cd /your-project-dir/

$ python manage.py startapp accounts

We have created a dedicated Django application for user management and authentication.

Create forms.py!

accounts/forms.py

Add these lines to models.py!

accounts/models.py

Add these lines to admin.py!

accounts/admin.py

Change AUTH_USER_MODEL for the Custom!

config/settings.py
INSTALLED_APPS = [ ... 'accounts', ] # Add this to the end! AUTH_USER_MODEL = 'accounts.CustomUser'

Migrate your models

Open your command-line interface or shell!

Always be sure if virtual environment is running ($ pipenv shell)!

By now, you can make migrations and migrate your models to the database.

"Migrations are Django’s way of propagating changes you make to your models (adding a field, deleting a model, etc.) into your database schema." https://docs.djangoproject.com/...

$ python manage.py makemigrations

$ python manage.py migrate

Create superuser

$ python manage.py createsuperuser

After that you have to add your username, email and password. If you have done you are able to access the admin interface on http://127.0.0.0.1:8000/admin.