flask-sqlalchemy

How do I update the password?

How do I update the password? Question: I am working on a web app and I want a user to be able to reset their password but I’m failing to do so how can I do it? I also tried email = request.form.get(’email’) new_password = request.form.get(‘password’) user = User.query.filter_by(email=email).first() If user : user.password = new_password. …

Total answers: 1

config flask app with a app.config.from_object

config flask app with a app.config.from_object Question: I have a flask app with MySQL DB i want to config my app with config.formobject(object) Then, I write the following class: import os class Config: DEBUG = True TESTING = False SESSION_COOKIE_SECURE = True SQLALCHEMY_DATABASE_URI = "mysql+pymysql://root:tool789@localhost/city’" SQLALCHEMY_TRACK_MODIFICATIONS = False SECRET_KEY = os.urandom(24) MAIL_SERVER = "Yourdomain" MAIL_USERNAME …

Total answers: 1

db.create_all() on flask doesn't create database file

db.create_all() on flask doesn't create database file Question: I’m unable to create a SQLite database file with Flask-SQLAlchemy. This was working before. It doesn’t show an error or warning, but it doesn’t create the SQLite file. I also tried creating the database from the terminal but that didn’t work either. from flask import Flask from …

Total answers: 2

FTS5 on sqlite through SQLalchemy

FTS5 on sqlite through SQLalchemy Question: My goal is to use SQLAlchemy to access a FTS5 table in sqlite3, with the virtual tables being updated at each insert. To this end, after doing some research (see this answer), I have coded the following: class CreateFtsTable(DDLElement): """Represents a CREATE VIRTUAL TABLE … USING fts5 statement, for …

Total answers: 1

Unable to create database when running flask app

Unable to create database when running flask app Question: I’m new to flask and I got stuck into one thing. So I have run.py file inside it from market import app from market.models import db if __name__ == "__main__": with app.app_context(): db.create_all() app.run(debug=True) so when I call python run.py the db.create_all() function works. But when …

Total answers: 3

Python SQLAlchemy PostgreSQL find by primary key Deprecate message

Python SQLAlchemy PostgreSQL find by primary key Deprecate message Question: I use below code to find the object by primary key. Now I am getting this Deprecated features detected message. How can I re-write this query to fix the deprecated message. Code: def find_by_id(self, obj_id): with self.session() as s: x = s.query(User).get(obj_id) return x Warning: …

Total answers: 1

Python SQLAlchemy PostgreSQL Deprecated API features

Python SQLAlchemy PostgreSQL Deprecated API features Question: I am using following code to create the function and trigger to update the created_at and updated_at fields. with upgrade of new module getting the deprecated API warning. How can I replace engine.execute(sa.text(create_refresh_updated_at_func.format(schema=my_schema))) line to remove the warning message? Code: mapper_registry.metadata.create_all(engine, checkfirst=True) create_refresh_updated_at_func = """ CREATE OR REPLACE …

Total answers: 1

Iterate through a Python Flask-sqlalchemy Query Result as a list comprehension

Iterate through a Python Flask-sqlalchemy Query Result as a list comprehension Question: I have a flask-sqlalchemy query which returns a list of alert data. alert_data = Alerts.query.filter_by(alertRemediated = False).all() I am iterating through the result with the below code to count all "Critical" alerts. This code works, but seem inefficient. c = 0 for alert …

Total answers: 2

Is it possible to query SQLAlchemy Joined Table Inheritance with and condition

Is it possible to query SQLAlchemy Joined Table Inheritance with and condition Question: Using flat models, it is possible to do the following join: session.query( EmployeeModel.name, EmployeeDepartment.dept_name ).join( EmployeeDepartment, and_( EmployeeDepartment.employee_id == EmployeeModel.id, EmployeeDepartment.dept_code == ‘P01′ ) ).all() In my case I have the following inheritance hierarchy: `class Parent(Base): tablename = ‘parent’ id = Column(BigInteger, …

Total answers: 1

SQLAlchemy cannot find referenced table via foreignkey in many-to-many relationship

SQLAlchemy cannot find referenced table via foreignkey in many-to-many relationship Question: I have already succeeded in adding one many-to-many relationship in my database. However, when trying to add another, I am met with: sqlalchemy.exc.NoReferencedTableError: Foreign key associated with column ‘user_shiftTemplate.template_id’ could not find table ‘shifttemplate’ with which to generate a foreign key to target column …

Total answers: 2