Issue
Using django 1.7.7 I want to use django's migration to add or remove a field. so I modified model.py and ran
python manage.py makemigrations myproj
Migrations for 'myproj':
0001_initial.py:
- Create model Interp
- Create model InterpVersion
python manage.py migrate myproj
Operations to perform:
Apply all migrations: myproj
Running migrations:
Applying myproj.0001_initial... FAKED
python manage.py runserver
Then checked the admin page, it is not updated. Then I tried removing the migration folder and tried again; the migrate command says there are no migrations to apply.
How can I do the migration? Note: I want to use the new technique using django's migration not the old south approach.
Solution
Deleting the migration directory is never a good idea, because Django then loses track of which migration has been applied and which not (and once an app is deployed somewhere it can become quite difficult to get things back in sync).
Disclaimer: whenever things like that occur it is best to backup the database if it contains anything valuable. If in early development it is not necessary, but once things on the backend get out of sync there is a chance of things getting worse. :-)
To recover, you could try resetting your models to match exactly what they were before you have added/removed the fields. Then you can run
$ python manage.py makemigrations myproj
which will lead to an initial migration (0001_initial...
). Then you can tell Django to fake that migration, which means to tell it to set its internal counter to this 0001_initial
:
With Django 1.7:
$ python manage.py migrate myproj
With Django >= 1.8:
$ python manage.py migrate myproj --fake-initial
Now, try to change your model and run makemigrations
again. It should now create a 0002_foobar
migration that you could run as expected.
Answered By - sthzg
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.