techwithtim / Flask-Web-App-Tutorial

Code for the note storing flask web app made during a YouTube video.
918 stars 1.01k forks source link

Database not being created. #158

Open ScalvyC opened 1 month ago

ScalvyC commented 1 month ago

Code: "from flask import Flask from flask_sqlalchemy import SQLAlchemy from os import path

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

def create_app(): app = Flask(name) app.config['SECRET_KEY'] = 'www' 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='/')

from .models import Admin, Employees, Product, Order, OrderItem, InventoryPage, Supplier

create_database(app)
with app.app_context():
    db.create_all()

return app

def create_database(app): if not path.exists('Website/' + DB_NAME): db.create_all(app=app) print('Created Database!') "

Error: "S D:\MY PC\Documents> & "C:/Program Files/Python312/python.exe" "d:/MY PC/Documents/main.py" Traceback (most recent call last): File "d:\MY PC\Documents\main.py", line 3, in app = create_app() ^^^^^^^^^^^^ File "d:\MY PC\Documents\Website__init.py", line 22, in create_app create_database(app) File "d:\MY PC\Documents\Website\init__.py", line 30, in create_database db.create_all(app=app) TypeError: SQLAlchemy.create_all() got an unexpected keyword argument 'app'"