0

I've been following basic tutorial on how to create a web application with a Postgres DB. Not sure what I'm doing wrong and could use some help.

I've seen two other similar questions here on SO but I am not getting any of the errors that those folks are getting but neither are the tables being created.

I have the following code in app.py:

from flask import Flask, render_template, request
from flask.ext.sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config['SQLAlchemy_DATABASE_URI']=
    'postgresql://postgres:password@localhost/
Height_collector'
db=SQLAlchemy(app)

class Data(db.Model):
    __tablename__="data"
    id=db.Column(db.Integer, primary_key=True)
    email_=db.Column(db.String(120), unique=True)
    height_=db.Column(db.Integer)

    def __init__(self, email_, height_):
        self.email_=email_
        self.height_=height_

the tutorial then has me to to the command prompt, run python, then:

from app import db

Which returns the following error:

'Neither SQLALCHEMY_DATABASE_URI nor SQLALCHEMY_BINDS is set. ' 
C:\admSh\FlaskApp\venv\lib\site-packages\flask_sqlalchemy\__init__.py:794: 
FSADe precation Warning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant 
overhead and will be disabled by default in the future.  Set it to True or 
False to suppress this warning.

I then type:

db.create_all()

The tutorial magically shows the tables being created but my tables aren't created. I'm table-less :( Anyone know what I can do?

1 Answer 1

1

The config properties are case sensitive (actually they will ignore anything not uppercase)

app.config['SQLAlchemy_DATABASE_URI']

should be

app.config['SQLALCHEMY_DATABASE_URI']
Sign up to request clarification or add additional context in comments.

2 Comments

thank you thank you. I've been going cross-eyed looking at this!
Not directly related. Ensure app.config['SQLAlchemy_DATABASE_URI'] is before db=SQLAlchemy(app) to avoid 'Neither SQLALCHEMY_DATABASE_URI nor SQLALCHEMY_BINDS is set. ' error.

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.