Answers for "django migrate add new field to existing table"

0

django migrate add new field to existing table

Initialize migrations for your existing models:

./manage.py makemigrations myapp
Fake migrations for existing models:

./manage.py migrate --fake myapp
Add the new field to myapp.models:

from django.db import models

class MyModel(models.Model):
    ... #existing fields
    newfield = models.CharField(max_length=100) #new field
Run makemigrations again (this will add a new migration file in migrations folder that add the newfield to db):

./manage.py makemigrations myapp
Run migrate again:

./manage.py migrate myapp
Posted by: Guest on April-14-2021

Code answers related to "django migrate add new field to existing table"

Python Answers by Framework

Browse Popular Code Answers by Language