How to add a new field to a model with new django migrations? -
i'm using contribute_to_class
method don't know how create field in db new migrations.
to reply question, new migration introduced in django 1.7, in order add together new field model can add together field model , initialize migrations ./manage.py makemigrations
, run ./manage.py migrate
, new field added db. avoid dealing errors existing models however, can utilize --fake
:
initialize migrations existing models:
./manage.py makemigrations myapp
fake migrations existing models:
./manage.py migrate --fake myapp
add new field myapp.models:
from django.db import models class mymodel(models.model): ... #existing fields newfield = models.charfield(max_length=100) #new field
run makemigrations 1 time again (this add together new migration file in migrations folder add together newfield db):
./manage.py makemigrations myapp
run migrate again:
./manage.py migrate myapp
django django-models django-1.7 django-migrations
No comments:
Post a Comment