Recover dropped table in Django : Table doesn't exist

a quick fix for Django : Table doesn't exist error.

Advert

It's accidental to delete a table when performing some actions or on purpose to get rid of cluster. Django has a good in-build engine that can manage the changes in models and your database synced but if you happen to drop a migrated table you will end up with Django : Table doesn't exist. Here's how you can fix it.

  • Drop tables ( you most probably completed :p )
  • Comment-out the model in models.py and other locations where the model is induced, else System-checks will fail
  • if django version >= 1.7 for older see below
    
    python manage.py makemigrations
    python manage.py migrate --fake
    
  • comment-in your model in models.py
  • Run makemigrations and migrate again without using --fake
  • You are back on track.

    Note: This does not bring back the data lost when you dropped the table, it recreates the database table and allows further use of application

    If you have django version less than 1.7 use schemamigration to get the magic:

    
    python manage.py schemamigration  --auto
    python manage.py migrate someapp --fake
    

Comments

Wow ! you have someting to tell us. That's great! Please keep in mind that comments are moderated, we employ rel="nofollow" for links, avoid using a spammy word or a domain in name field, it might end up as a Spam. Thanks for reading.

Last 5 Articles

All Articles >

  1. Domain Authority

     
  2. Public Endpoint in Django Rest Framework

     
  3. 4 Ways to Increase Conversion Rates using Videos

     
  4. Getting the best customer experience analytics solutions

     
  5. How to Remove an App from Django Project

     

News Letter

Subscribe to our email newsletter for useful tips and valuable resources, sent out every new article release.