Production-Ready Method of Extending Django User Model in Mid-Project

Lev Maximov
The Startup
Published in
11 min readMay 31, 2020

--

Background design by freepik

In Django, a python web framework, the User model is locked in with a relatively small set of fields that is supposed to be necessary and sufficient for all use cases. In fact, who would ever want fields like department name, date of birth, passport or social security number directly in the User model, readily editable through the native django “edit user” admin page?

The official documentation gives instructions on how to do it if when starting a project but as for the ongoing project it says: “This change can’t be done automatically”. In this article, there is a short walk-through of how to add fields directly to the auth_user database table in django 3.0 relatively easily keeping all the existing database tables in place, with all the migrations files and records intact, without running any raw SQL commands manually in dbshell and (optionally) without creating fake migrations.

If you are pressed for time you can skip directly to the “Preparation” section. But if you want to have a better idea of what is going on under the hood, read on.

Disclaimer: this method is not yet officially approved by the django team; some details might change in future; use it with care; make backups, write tests.

Introduction

--

--