Maxikilliane / DH_MusicAnalysis

0 stars 0 forks source link

Migrate DB to Postgres to enable Heroku Hosting #65

Closed blueCat11 closed 5 years ago

blueCat11 commented 5 years ago

I garnered from here that sqlite3 (our current db) is not suitable for use with heroku. So I tried to change to postgres (at least locally) which caused lots of problems (including the one which is hogging our public version, so I think the switch should be made for that, too, since ultimately things are running again for me - at least locally).

Here is what I did:

  1. install postgres sql locally. (https://www.enterprisedb.com/downloads/postgres-postgresql-downloads)
  2. start a postgres database to use in local testing (I called it beyond_the_notes, but that's not really relevant)
  3. Change the database in settings.py to the local database. You will have to run python manage.py makemigrations and python manage.py migrate at this point, to get the tables into the new database. If things are the same as they were for me, you will get errors saying that tables don't exist (for me, it was django_sessions).
  4. To circumvent those errors, do the following:
    1. totally comment out every bit of python code that could possibly be affected by the database., except models.py . I commented out choice.py, session_handling.py, views.py, and forms.py . Use triple quotes for speed.
    2. I added a try catch block around the urls, like in this stackoverflow answer, otherwise, you will have to comment out the urlpatterns as well
    3. run "python manage.py makemigrations"
    4. run "python manage.py migrate", but not all at once, run the migrate statements one by one for the different apps, like so "python manage.py migrate sessions python mange.py migrate contenttypes python manage.py migrate auth python manage.py migrate admin python manage.py migrate MusicAnalyzer"
  5. You should now see the created tables in your local postgre database, and a final general "python manage.py migrate" should run through without errors.
blueCat11 commented 5 years ago

To switch the deployment db as well, I followed parts of this tutorial, more specifically the python parts. You will notice that some changes in this branch are to the settings.py. Like in this tutorial, I have added a local_settings.py, which is in our shared dropbox DH folder, so you know what I did there. You will have to change it to hold your own db settings, and add it to the same folder where the settings.py is.