I have accidentally dropped a table in Django 1.7 project. I ran makemigrations
& migrate
. Both commands didn't recognized that table has dropped. So they had no affect.
Should I remove code for the model, make migration, add the code for the model & again migrate? Or is there a better way to recover it?
Try this:
python manage.py sqlmigrate app_name 0001 | python manage.py dbshell
It pipes the output of the initial app migration to dbshell, which executes it. Split it up in two steps and copy/paste the SQL commands if you'd like more control over what's happening.
Naturally the migration contains a single transaction for all the app's tables, so if it is only a single table that is missing (from a multi-model app) you'd have to manually pick only the table you want to recreate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With