I'm currently trying to build a small flash drive app. This is my structure.
run.py application __init__.py database.py models.py views.py
database.py contains only the SQLAlchemy object:
db = SQLAlchemy()
Then I import it into my models.py to create my models. Finally, inside __init__.py I import db from database.py and do:
from .database import db from flask import Flask app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///application.db' db.init_app(app) db.create_all()
However, I cannot create tables from the models that appeared. If I remove db.create_all() . The application will work without problems, but, obviously, the database is not created. When db.create_all() present, I get "RuntimeError: an application not registered on the db instance and the application is not bound to the current context."
I was honestly confused, because before I had problems running the application without creating a database, but moving db to its own file seems to somehow fix this problem. Now there remains only the problem of creating the database.
Can someone tell me what could be the problem? I am sincerely dead end.
source share