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:
- undo the change of models.py
- do the django migration (
manage.py makemigrations appname
works better thanmanage.py makemigrations
) - if the migration works, then change the models.py again
- do the django migration again
this works sometimes.
I was able to solve this issue by the following steps
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.
I've run the command again
python manage.py migrate app_name zero
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.