Skip to content

RuntimeError: SQLAlchemy_DATABASE_URI must be set #106

@Sayinq

Description

@Sayinq

`from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from os import path

db = SQLAlchemy()
DB_NAME = "database.db"

def create_app():
app = Flask(name)
app.config['SECRET_KEY'] = 'beepboopbrainkey'
app.config['SQLAlchemy_DATABASE_URI'] = f'sqlite:///{DB_NAME}'
db.init_app(app)

from .views import views
from .auth import auth

app.register_blueprint(views, url_prefix='/')
app.register_blueprint(auth, url_prefix='/')

#Check for user database
from .models import User, Note #Defined classes

create_database(app)

return app

#Checking if database exists
def create_database(app):
if not path.exists('website/' + DB_NAME): #Does it exist?
with app.app.context():
db.create_all(app=app) #Creates if not
print('Created Database!')`

Following along but ran into this error when implementing Database check:
RuntimeError: Either 'SQLALCHEMY_DATABASE_URI' or 'SQLALCHEMY_BINDS' must be set.
But it is obviously set.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions