Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

Thanks.

like image 520
Programmingjoe Avatar asked Sep 26 '22 07:09

Programmingjoe


2 Answers

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.

like image 188
Rahul Jain Avatar answered Sep 28 '22 23:09

Rahul Jain


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.

like image 30
Anzel Avatar answered Sep 29 '22 00:09

Anzel