osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

creating a table within python code


I'm working on my first python project in CS50W  and I am trying to create
2 tables.
I am getting the following error when trying to run it:  I have included my
code below the error message.

flask.cli.NoAppException: Failed to find Flask application or factory in
module "create_db". Use "FLASK_APP=create_db:name to specify one.
Traceback (most recent call last)
File
"C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\_compat.py",
line 39, in reraise
raise value
File
"C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py",
line 97, in find_best_app
raise NoAppException(
flask.cli.NoAppException: Failed to find Flask application or factory in
module "create_db". Use "FLASK_APP=create_db:name to specify one.

I used:
FLASK_APP=create_db.py   at the command line

and this is my code:

import os
from flask import Flask, session
from flask_session import Session
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
engine = create_engine(os.getenv("DATABASE_URL"))
db = scoped_session(sessionmaker(bind=engine))
def main():
    db.execute("CREATE TABLE books (id SERIAL PRIMARY KEY, isbn VARCHAR NOT
NULL, title VARCHAR NOT NULL, author INTEGER NOT NULL, year INTEGER NOT
NULL,)")
    db.execute("CREATE TABLE authors (id SERIAL PRIMARY KEY, name VARCHAR
NOT NULL,)")
    db.commit()
if __name__ == "__main__":
    main()

Does anyone have any ideas?

Al (Buddy) Peacock, PMP, MCCT,  ITILv3, SMC, CSM, SPOC
(920) 740-3411
linkedin.com/in/buddypeacock <https://www.linkedin.com/in/buddypeacock/>