Application deploy flask in heroku with flask-sqlalchemy

0

Good afternoon.

I have a small application written in flask and I'm having problems with the database when trying to deploy in heroku and after searching for two days I did not find any solution that would meet me.

In summary, this is the code for my app:

from flask import Flask
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://postgres:1234@localhost/jperfil'
db = SQLAlchemy(app)
app.secret_key = '123456789'

#aqui vão os registros de algumas blueprints e imports de classes

db.create_all()

I can imagine that this is not how you set up a bank to deploy, even though these are the local bank settings, but how to configure so that heroku understands the settings and automatically creates my bank?

    
asked by anonymous 22.08.2018 / 20:34

1 answer

0

You need to add the database add-on to your heroku application (I confess I do not understand much of it, but following this tutorial here link you will be able to unroll).

Once you configure this step, the only thing you should worry about in your application is to start the database correctly using the create_all command (which you already do) and set the variable

SQLALCHEMY_DATABASE_URI = os.environ['DATABASE_URL']

In this way your application will get the connection string from the environment variable to the database made available by heroku and already started in your application.

    
22.09.2018 / 14:23