-1

I want to add more fields in User Data table so Please Explain the right method to done this.

  • 1
    https://docs.djangoproject.com/en/2.2/topics/auth/customizing/#extending-the-existing-user-model – iklinac Nov 04 '19 at 17:34

1 Answers1

0

it is very simple, in your models.py in the User model just simply add another field,

example:

class User(models.Model):
    name = models.CharField(max_length=100)
    phone = models.IntegerField()
    created_date = models.DateTimeField(default=timezone.now)
    modified_date = models.DateTimeField(default=timezone.now)

lets add the field email:

class User(models.Model):
    name = models.CharField(max_length=100)
    phone = models.IntegerField()
    email = models.CharField(max_length=100)
    created_date = models.DateTimeField(default=timezone.now)
    modified_date = models.DateTimeField(default=timezone.now)

then run this command in your terminal:

python manage.py makemigrations

and it will display the alter you are about to make and then run the command:

python manage.py migrate

and the new field will be added.I hope this helps you

Cheers!

Jorge López
  • 489
  • 3
  • 17