django migrate add new field to existing table

Solutions on MaxInterview for django migrate add new field to existing table by the best coders in the world

showing results for - "django migrate add new field to existing table"
Cara
01 Apr 2018
1Initialize migrations for your existing models:
2
3./manage.py makemigrations myapp
4Fake migrations for existing models:
5
6./manage.py migrate --fake myapp
7Add the new field to myapp.models:
8
9from django.db import models
10
11class MyModel(models.Model):
12    ... #existing fields
13    newfield = models.CharField(max_length=100) #new field
14Run makemigrations again (this will add a new migration file in migrations folder that add the newfield to db):
15
16./manage.py makemigrations myapp
17Run migrate again:
18
19./manage.py migrate myapp