How to add columns to auth_user in django postgresql?

Member

by domenico , in category: MySQL , a month ago

How to add columns to auth_user in django postgresql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by orpha , a month ago

@domenico 

To add columns to the auth_user table in Django with PostgreSQL, you can create a migration using the following steps:

  1. Create a new model with the additional fields you want to add to the auth_user table. For example, if you want to add a "phone_number" field, you can create a model like this:
1
2
3
4
from django.contrib.auth.models import AbstractUser

class CustomUser(AbstractUser):
    phone_number = models.CharField(max_length=20, blank=True, null=True)


  1. Run python manage.py makemigrations to create a migration file for the new model.
  2. Run python manage.py migrate to apply the migration and create the new table.
  3. Create a data migration (if needed) to populate the new columns with data.
  4. You may also need to update the User model in the admin panel to include the new fields.


By following these steps, you can add columns to the auth_user table in Django with PostgreSQL.