Home > Net >  Having a problem hosting with heroku (discord.py)
Having a problem hosting with heroku (discord.py)

Time:10-13

I connected my Github project to Heroku and every time I commit, Heroku restarts my app, and it overwrites my userDB.xlsx which resets the data. Can I save the file changes Heroku made and automatically commit to Github? I'm using python for my project. And use Visual Studio Code for coding.

I use this code for saving/loading userDB.xlsx

from openpyxl import *
import os

workbook_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),"userDB.xlsx")

wb = load_workbook(workbook_path)
ws = wb.active

def loadFile():
    wb = load_workbook(workbook_path)
    ws = wb.active
def saveFile():
    wb.save(workbook_path)
    wb.close()

CodePudding user response:

Heroku is not suitable for persistent storage of data. Heroku's filesystem is ephemeral so changes in the content of the files will be restored once your app get restarted.

The way you are trying to store persistent data won't work. The appropriate way is to have your data stored outside of the project filesystem and access / modify it from there when needed.

The best option in your case doesn't seems to be to have the database stored on your computer (so you can access to it even when your computer is off).

Heroku has database addons that allows you to store your database in a server. You can see the full list of addons here. A good choice would be the Postgres's database addon.

P.S.: You can use non-Heroku database alternatives even if your app is running on Heroku.

  • Related