flask-sqlalchemy

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:[email protected]/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: 1

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 column passed as dropdown list in WTForm Flask

SQLAlchemy column passed as dropdown list in WTForm Flask Question: I want to take the values of a column named hotelName from Hotel model and populate with them a dropdown list. I have tried this as a way to put them in my wtform: class RoomForm(FlaskForm): hotel = SelectField(choices=[(h, h) for h in Hotel.hotelName.property.columns[0].type But …

Total answers: 1

Fetch two columns from db using SQLalchemy

Fetch two columns from db using SQLalchemy Question: I am learning python and trying to create a drop-down in my form with the data from another table. here is my code Models.py class empmasterModel(db.Model): __tablename__ = "empmaster" Empnum = db.Column(db.Integer, primary_key=True) Employee_Number = db.Column(db.Integer(),primary_key=True,unique = True) Employee_Name = db.Column(db.String()) Employee_Type = db.Column(db.String()) Coreid = db.Column(db.String()) …

Total answers: 1