2
votes

I have been developing a Django project using sqlite3 as the backend and it has been working well. I am now attempting to switch the project over to use postgres as the backend but running into some issues.

After modifying my settings file, setting up postgres, creating the database and user I get the error below when running manage.py migrate

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

financemgr is an app within the project. rate is a table within the app.

If I run this same command but specify sqlite3 as my backend it works fine.

For clarity I will repeat:

Environment Config1

  • Ubuntu 14.04, Django 1.10
  • Settings file has 'ENGINE': 'django.db.backends.sqlite3'
    1. Run manage.py migrate
    2. Migration runs and processes all the migrations successfully

Environment Config2

  • Ubuntu 14.04, Django 1.10
  • Settings file has 'ENGINE': 'django.db.backends.postgresql_psycopg2'
    1. Run manage.py migrate
    2. Migration runs and gives the error django.db.utils.ProgrammingError: relation "financemgr_rate" does not exist

Everything else is identical. I am not trying to migrate data, just populate the schema etc.

Any ideas?

1
do you have such a model (called Rate?) - e4c5
I think you have pre-stored migration files(migrate for sqlite database) , now you have change the database configuration but still django looking for the existing table according to migration files you have. Better you delete all the migration files in migration folder in your app, and migrate it again, it may work fine. - Piyush S. Wanare
Hi @PiyushS.Wanare , yes you are correct. I had to delete the old migration files and it worked. Would you like to put that in an answer and then I can accept it? - James
Yup Thanks @James - Piyush S. Wanare

1 Answers

2
votes

This may help you :

I think you have pre-stored migration files(migrate for sqlite database). Now you have change the database configuration but still django looking for the existing table according to migration files you have(migrated for previous database). Better you delete all the migration files in migration folder of your app, and migrate it again, by running commands python manage.py makemigrations and python manage.py migrate it may work fine.