Reputation: 1417
I am attempting to move an SQLite database to Heroku using Flask so I can access it from a few devices. I am pushing the database to Heroku which I have created locally, so I know that the table exists.
Client.py
import requests, json
url = "https://someidijustmadeup.herokuapp.com/select"
j = {}
j["sql"] = "SELECT * FROM COMICS"
r = requests.get(url, json = j)
print("Status Code", r.status_code)
rJson = json.loads(r.content.decode("utf-8"))
print(len(rJson))
Server.py
import os
from flask import (Flask, jsonify, request)
from functions.functions import (executeSqlRequest)
host = "0.0.0.0"
app = Flask(__name__)
@app.route("/select", methods = ["GET"])
def select():
rJson = request.get_json()
# Ignore the values, SELECT doesn't need them
returnDict = executeSqlRequest(rJson.get("sql", None), None)
return jsonify(returnDict)
if (__name__ == "__main__"):
port = int(os.environ.get("PORT", 5000))
app.run(host = host, port = port)
executeSqlRequest
simply queries the database. The actual Flask application is fine, I can connect to it and run the queries.
Info
cat database.db
remotely on the Heroku server and within the output I can see rows from the database so I know that the data is there. It also shows me the SQL for my table.Upvotes: 0
Views: 1087
Reputation: 136880
Heroku dynos have an ephemeral filesystem: any changes you make will be lost whenever the dyno restarts, which happens frequently (at least once per day). Since SQLite is a file-based database it is incompatible with Heroku.
The good news is that Heroku has good support for client-server databases like PostgreSQL. In fact, it provides a PostgreSQL database by default. The DATABASE_URL
environment variable will give you coordinates for connecting to that database.
If Postgres isn't your speed you can pick another data store from the list of addons.
Upvotes: 2