Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django 1.7 - Accidentally Dropped One Table. How To Recover It?

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?

like image 831
Pandikunta Anand Reddy Avatar asked Sep 08 '14 13:09

Pandikunta Anand Reddy


1 Answers

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.

like image 60
Simon Avatar answered Oct 15 '22 01:10

Simon