darkpool
darkpool

Reputation: 14641

Django migrations: relation does not exist

I have a working site and database on my dev server which I am trying to setup on a live server. I am doing the following:

I get the error: django.db.utils.ProgrammingError: relation "myapp_mytable" does not exist.

I can't seem to get the initial migration to happen. The only solution I have found is to go into my settings.py file and comment out all my apps within INSTALLED_APPS and go into my main urls.py file and comment out all my urls.

After commenting out those sections, I am able to do the initial migration. After that I can then uncomment my apps and start migrating them one by one, ie: python manage.py makemigrations appname then python manage.py migrate

So I have a workaround but it is far from ideal. Surely there is a way to tell django that I have created a brand new empty database so it needs to do the initial migration first. I am automating the server setup with Ansible, so requiring me to do all of this manual comment/uncomment and multiple migrations is not good.

UPDATE:

As per the comments, I am not suppose to delete the migrations. So I did the following on the dev server to try and recreate them: link. However even though I now have migration files which I have copied to the live server, when I try run them I get the same error as above.

I have read through the migration files and I don't see anything that mentions creating the initial migration / database schema. It only mentions creating my app models. I can't seem to figure out how to do the initial migration before the app migrations can be done. I need to somehow recreate all the migration files (including creating the initial db schema) from scratch so they can be run on the server.

Upvotes: 2

Views: 2214

Answers (1)

darkpool
darkpool

Reputation: 14641

I eventually figured out the issue thanks to @Daniel Roseman in the comments. I was doing the following:

list(Correlation().get_entries())

What this was doing was creating a model instance (ie: Correlation) and calling the get_entries() method against that. I then surrounded that in list(). For some reason, that was stopping the migrations from working. I removed the list() which wasn't necessary anyway, and it all works now.

Upvotes: 3

Related Questions