[Solved] Django – Relation “relation” does not exist. Cannot run python manage.py migrate?

So I was being stupid and I went to delete one of the tables in my django app so opened up psql and ran “Drop table ;” and dropped the table. Then I deleted my model and ran “python manage.py migrate” and I get this error…

django.db.utils.ProgrammingError: relation "textchange_myuser" does not exist

among other stuff above it.

So now I can’t delete the table properly and I can’t get it back. What do I do?


Solution #1:

As per my comment, in your situation you might run:

python manage.py migrate yourapp --fake

to “fake” applying the migration but not actually alter your database.

You can read more HERE

Hope this helps.

Respondent: Programmingjoe

Solution #2:

I deleted a table from postgres and then django was unable to detect the change. I tried everything but django didn’t created a new table. Finally I fixed this with some alternate way.

login to your database create table manually.
– Get the create command from django itself.

python manage.py sqlmigrate 'yourapp' 001

this will give you the initial command django used to create the table.

one by one get all the migrations and execute commands on database by command line.

Respondent: Anzel

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.