5

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.

Programmingjoe
  • 2,169
  • 2
  • 26
  • 46

2 Answers2

3

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.

Rahul Jain
  • 3,065
  • 1
  • 13
  • 17
2

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.

Anzel
  • 19,825
  • 5
  • 51
  • 52