[Python] TypeError: SQLAlchemy.create_all() got an unexpected keyword argument 'app' , why and...

Discussão em 'Python' iniciado por Stack, Março 9, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to create a website for teachers and students, I'm still working on the authorisation aspect of this problem and don't have the most experience, that's why I was wondering someone could please tell me where I've gone wrong[text]

    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'] = 'meow'
    app.config['SQLALCHEMY_DATABASE_URI'] = f'sqlite:///{DB_NAME}'

    db.init_app(app)


    from .views import views
    from .authorisation import authorisation

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

    from .models import Student, Teacher, Grade

    create_database(app)

    return app

    def create_database(app):
    if not path.exists('website/' + DB_NAME):
    db.create_all(app = app)
    print('Create database.')



    I used a function from SQLalchemy called create_all in a function called create_database with the idea that if the database doesn't exist it gets created, I am also following a tutorial and changing it to fit what I want to create along the way but the code that worked for the YouTuber isn't for me and the only difference is the objects I created in my models library

    Continue reading...

Compartilhe esta Página