0

I am trying to connect my flask app to Heroku database. I tried a million thinks and aways getting the same error message : error mesage

From the terminal, I am logging in to my app DB and getting the following message:

You are connected to database "dclhb9ntogjjr" as user "ikkcwdbfbqzfiw" on host "ec2-54-195-247-108.eu-west-1.compute.amazonaws.com" (address "54.195.247.108") at port "5432". SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)

I tried to set variable DATABASE_URL=" ??????",but I am not sure how to get my DB URL from Heroku. If you have any ideas how to fix that please let me know.

2 Answers 2

1

First make sure that you Heroku Database is setup correctly.

Next you SHOULDN'T set the value of DATABASE_URL

The DATABASE_URL is a environment variable. To acces it you need this code

import os
database_url=os.environ.get('DATABASE_URL')
Sign up to request clarification or add additional context in comments.

Comments

0

Same happens even after I add it.

import os

from flask import Flask, session
from flask_session import Session
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker

app = Flask(__name__)

# Check for environment variable
if not os.getenv("DATABASE_URL"):
    raise RuntimeError("DATABASE_URL is not set")

# Configure session to use filesystem
app.config["SESSION_PERMANENT"] = False
app.config["SESSION_TYPE"] = "filesystem"
database_url=os.environ.get('DATABASE_URL')

# Set up database
engine = create_engine(os.getenv("DATABASE_URL"))
db = scoped_session(sessionmaker(bind=engine))
database_url=os.environ.get('DATABASE_URL')

@app.route("/")
def index():
    return "Project 1: TODO"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.