python - makemigrations does not work after deleting migrations -


i mistakenly deleted .py file under path projectname/appname/migrations, include like:

0001_initial.py

0011_auto_20150918_0723.py

0002_auto_20150819_1301.py

...

now, updated model file, , run command python manage.py makemigrations, prompt no changes detected.

how can recover everything?

first of all, even if happened in production, do not panic.

when deleted migrations django forgot app supposed managed migrations. django defaults legacy python manage.py syncdb migrationless behaviour , not attempt detect changes or generate new migrations when run python manage.py makemigrations

in order make aware of migrations, have run command app:

python manage.py makemigrations appname 

however, running application, django not able detect new migrations applied in database, , try run them again when run python manage.py migrate.

when happens migrations fail saying relation appname.xyz exists!.

to make django understand migration reflected in database have fake them:

python manage.py migrate appname --fake 

this update migration history table , mark migrations applied, not attempt create tables in database.

update (thanks @gwynbleid):

one concern here deleted migrations applied, listed in migrations history table in database. not problem initial python manage.py makemigrations myapp, other migrations raise error inconsistent migration history.

to avoid that, must remove hand row django_migrations table in database refers nonexistent migrations.


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -