Django + posgtres relation does not exist error

AFAIK, you should not directly delete a table from the DB before the migration. If you change your model, then manage.py migrate will do the thing.

django cannot detect the direct change of DB; only knows the change of model script. Therefore if you drop a table, then django does not detect the change, so django keeps looking for the table which was dropped and gives the error.

Sometimes migration does not work for no reasons. in that case, I do the following things:

  1. undo the change of models.py
  2. do the django migration ( manage.py makemigrations appname works better than manage.py makemigrations )
  3. if the migration works, then change the models.py again
  4. do the django migration again

this works sometimes.


I was able to solve this issue by the following steps

  1. when I was running this command

    python manage.py migrate app_name zero

    it was complaining about that some table is missing. so I've created a dummy table with a dummy column.

  2. I've run the command again

    python manage.py migrate app_name zero

  3. I've applied the migrations for that app

    python manage.py migrate app_name


What helped finally was deleting the whole migrations folder from the project's folder. Saw some south responses as well, but haven't tried.