flask-sqlalchemy

flask sqlalchemy many to many relationship with extra field

微笑、不失礼 提交于 2020-12-29 09:11:57
问题 I have 2 tables: restaurants and foods, and a 3rd table restaurants_foods which stores the many to many relationship between the 2 tables restaurants_foods = db.Table('restaurants_foods', db.Column('restaurant_id', db.Integer, db.ForeignKey('restaurants.id'), primary_key=True), db.Column('food_id', db.Integer, db.ForeignKey('foods.id'), primary_key=True), db.Column('food_price', db.Float) ) class Food(Model): __tablename__ = "foods" id = db.Column(db.Integer, primary_key=True, autoincrement

flask sqlalchemy many to many relationship with extra field

谁说胖子不能爱 提交于 2020-12-29 09:06:31
问题 I have 2 tables: restaurants and foods, and a 3rd table restaurants_foods which stores the many to many relationship between the 2 tables restaurants_foods = db.Table('restaurants_foods', db.Column('restaurant_id', db.Integer, db.ForeignKey('restaurants.id'), primary_key=True), db.Column('food_id', db.Integer, db.ForeignKey('foods.id'), primary_key=True), db.Column('food_price', db.Float) ) class Food(Model): __tablename__ = "foods" id = db.Column(db.Integer, primary_key=True, autoincrement

flask sqlalchemy many to many relationship with extra field

天大地大妈咪最大 提交于 2020-12-29 09:06:20
问题 I have 2 tables: restaurants and foods, and a 3rd table restaurants_foods which stores the many to many relationship between the 2 tables restaurants_foods = db.Table('restaurants_foods', db.Column('restaurant_id', db.Integer, db.ForeignKey('restaurants.id'), primary_key=True), db.Column('food_id', db.Integer, db.ForeignKey('foods.id'), primary_key=True), db.Column('food_price', db.Float) ) class Food(Model): __tablename__ = "foods" id = db.Column(db.Integer, primary_key=True, autoincrement

SQL Alchemy Won't Drop Tables at end of Test due to MetaData Lock on db

对着背影说爱祢 提交于 2020-12-06 13:51:16
问题 I am working on testing my flask app model. I'm using mysql 5.7, sqlalchemy and pytest. Within my model, I have a CRUD mixin that I used to manage creating, updating and deleting. Whenever I try to access the object in the Mixin before returning the object to the test function, SQLAlchemy hangs at db.drop_all in my tear down. When I look in mysql at PROCESSLIST, it shows 1 sleep query and 1 query waiting for table metadata lock. I can fix this by calling db.session.commit in the create method

SQL Alchemy Won't Drop Tables at end of Test due to MetaData Lock on db

ε祈祈猫儿з 提交于 2020-12-06 13:50:32
问题 I am working on testing my flask app model. I'm using mysql 5.7, sqlalchemy and pytest. Within my model, I have a CRUD mixin that I used to manage creating, updating and deleting. Whenever I try to access the object in the Mixin before returning the object to the test function, SQLAlchemy hangs at db.drop_all in my tear down. When I look in mysql at PROCESSLIST, it shows 1 sleep query and 1 query waiting for table metadata lock. I can fix this by calling db.session.commit in the create method

Why is my flask-sqlalchemy delete query failing

一个人想着一个人 提交于 2020-12-01 08:38:50
问题 I have a query using flask-sqlalchemy in which I want to delete all the stocks from the database where there ticker matches one in a list. This is the current query I have: Stock.query.filter(Stock.ticker.in_(new_tickers)).delete() Where new_tickers is a list of str of valid tickers. The error I am getting is the following: sqlalchemy.exc.InvalidRequestError: Could not evaluate current criteria in Python: "Cannot evaluate clauselist with operator <function comma_op at 0x1104e4730>". Specify

how to serialise a enum property in sqlalchemy using marshmallow

蹲街弑〆低调 提交于 2020-11-28 04:54:21
问题 this is my model class class Type(enum.Enum): Certified = "certified" Non_Certified = "non-certified" class Status(enum.Enum): Approved = "Approved" Rejected = "Rejected" Published = "Published" Retired = "Retired" Waiting_for_Approval = "Waiting_for_Approval" class DifficultyLevel(enum.Enum): Beginner = "Beginner" Intermediate = "Intermediate" Advanced = "Advanced" All = "All" class ActiveStatus(enum.Enum): Archive = "archive" Restore = "restore" class Course(Base): __tablename__ = 'course'

Query One to Many Relationship SQLAlchemy

。_饼干妹妹 提交于 2020-11-27 04:05:42
问题 I am trying to query the users based upon their skills from these tables. class User(UserMixin, db.Model): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(64), unique=True, index=True) username = db.Column(db.String(64), unique=True, index=True) skills = db.relationship('Skill', backref='author', lazy='dynamic') class Skill(db.Model): __tablename__ = 'skills' id = db.Column(db.Integer, primary_key=True) skill = db.Column(db.String(64), index

How to fix my approach to use the same models in vanilla SQLAlchemy and Flask-SQLAlchemy?

眉间皱痕 提交于 2020-11-25 03:26:18
问题 I came across several approaches on how to use the vanilla SQLAlchemy models in Flask-SQLAlchemy. It works like a charm to use models that inherit from Base with Flask-SQLAlchemy. But I really like that convenience stuff... Job.query.all() # Does not work db.session.query(Job).all() # Works So I started to work on this and put together some code, but I am stuck and need some help to get this nice and clean. The following block is a general definition that does not inherit from either. It is