Kaworu
Active Coder
Hi!
I am still trying to learn Flask. And I have some problems that I cannot fix myself.
Okay, so now I have a code (classes) that define a database. And I would like to generate the database in flash shell. However, I have some fundamental error with my database, yet I do not know why.
My code:
And the error I get when I run flask shell in cmd:
I feel very lost (also, it’s my first time ever doing something like this). Any help would be greatly appreciated ;-)
I am still trying to learn Flask. And I have some problems that I cannot fix myself.
Okay, so now I have a code (classes) that define a database. And I would like to generate the database in flash shell. However, I have some fundamental error with my database, yet I do not know why.
My code:
Python:
from flask import Flask, render_template, session, redirect, url_for, flash
from flask_bootstrap import Bootstrap
from flask_moment import Moment
from datetime import datetime
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField
from wtforms.validators import DataRequired
import os
from flask_sqlalchemy import SQLAlchemy
basedir = os.path.abspath(os.path.dirname(__file__))
app = Flask(__name__)
bootstrap = Bootstrap(app)
moment = Moment(app)
db = SQLAlchemy(app)
app.config["SQLALCHEMY_DATABASE_URL"] = "sqlite:///" + os.path.join(basedir, "my-database.db")
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
app.config["SECRET_KEY"] = "guess me!!!"
db.init_app(app)
# then go classes, routes etc – I believe everything there is fine, so I am not spamming you
And the error I get when I run flask shell in cmd:
Code:
Traceback (most recent call last):
File "C:\Users\DELL\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\DELL\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python310\Scripts\flask.exe\__main__.py", line 7, in <module>
File "C:\Users\DELL\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\cli.py", line 1064, in main
cli.main()
File "C:\Users\DELL\AppData\Roaming\Python\Python310\site-packages\click\core.py", line 1055, in main
rv = self.invoke(ctx)
File "C:\Users\DELL\AppData\Roaming\Python\Python310\site-packages\click\core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "C:\Users\DELL\AppData\Roaming\Python\Python310\site-packages\click\core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "C:\Users\DELL\AppData\Roaming\Python\Python310\site-packages\click\core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "C:\Users\DELL\AppData\Roaming\Python\Python310\site-packages\click\decorators.py", line 26, in new_func
return f(get_current_context(), *args, **kwargs)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\cli.py", line 355, in decorator
app = __ctx.ensure_object(ScriptInfo).load_app()
File "C:\Users\DELL\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\cli.py", line 313, in load_app
app = locate_app(import_name, None, raise_if_not_found=False)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\cli.py", line 219, in locate_app
__import__(module_name)
File "E:\Personal Data\My Folders\Programowanie\Python3\Flasky\My Code\5\SQLAlchemy\app.py", line 21, in <module>
db = SQLAlchemy(app)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python310\lib\site-packages\flask_sqlalchemy\extension.py", line 278, in __init__
self.init_app(app)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python310\lib\site-packages\flask_sqlalchemy\extension.py", line 355, in init_app
raise RuntimeError(
RuntimeError: Either 'SQLALCHEMY_DATABASE_URI' or 'SQLALCHEMY_BINDS' must be set.
I feel very lost (also, it’s my first time ever doing something like this). Any help would be greatly appreciated ;-)