-
So far I used the following code to set the from flask_security import SQLAlchemyUserDatastore
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import Column, Integer
from sqlalchemy.ext.declarative import declared_attr, declarative_base
_Base = declarative_base()
class BaseModel(_Base):
"""Base model for database objects
The base model contains a `id` column as primary key
"""
__abstract__ = True
@declared_attr
def __table_args__(cls):
return {
"mysql_engine": "InnoDB",
}
id = Column(Integer, primary_key=True)
db: SQLAlchemy = SQLAlchemy(model_class=BaseModel) This was working as expected and the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
This was an oversight while rewriting the code, I'll add In general, it's required to subclass Flask-SQLAlchemy classes to get Flask-SQLAlchemy behaviors. Note that you're also missing out on other behaviors, such as automatic table names, bind keys, and a nice However, the entire |
Beta Was this translation helpful? Give feedback.
This was an oversight while rewriting the code, I'll add
model.query
for existing bases back in.In general, it's required to subclass Flask-SQLAlchemy classes to get Flask-SQLAlchemy behaviors. Note that you're also missing out on other behaviors, such as automatic table names, bind keys, and a nice
repr
.However, the entire
query
interface is considered legacy in SQLAlchemy now. See the discussion in their docs. SQLAlchemy wants you to move todb.select(User)
to construct queries, anddb.session.execute(q)
to execute them.