- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我没有使用 sqlalchemy 的经验,我有以下代码:
class ForecastBedSetting(Base):
__tablename__ = 'forecast_bed_settings'
__table_args__ = (
Index('idx_forecast_bed_settings_forecast_id_property_id_beds',
'forecast_id', 'property_id',
'beds'),
)
forecast_id = Column(ForeignKey(u'forecasts.id'), nullable=False)
property_id = Column(ForeignKey(u'properties.id'), nullable=False, index=True)
# more definition of columns
__table_args__
的目的是什么,所以我不知道这条线在做什么:
__table_args__ = (
Index('idx_forecast_bed_settings_forecast_id_property_id_beds',
'forecast_id', 'property_id',
'beds'),
)
__table_args__
的目的是什么吗? ,以及前一段代码在做什么。
最佳答案
This attribute accommodates both positional as well as keyword arguments that are normally sent to the
Table
constructor.
ForecastBedSetting
在您的情况下 -
Base
附带的元类
creates an instance of Table
.
__table_args__
属性允许将额外的参数传递给
Table
.创建的表可以通过
ForecastBedSetting.__table__
Index
实例到创建的
Table
.索引使用字符串名称来标识列,因此如果没有传递给表,SQLAlchemy 无法知道它属于哪个表。
关于python - sqlalchemy 中 __table_args__ 的目的是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43455126/
我发现如果 __table_args__ 存在于单表继承设置中的子类中,SQLAlchemy 会抛出 sqlalchemy.exc.ArgumentError: Can't place __table
我没有使用 sqlalchemy 的经验,我有以下代码: class ForecastBedSetting(Base): __tablename__ = 'forecast_bed_set
假设我有这样的表 class Base(object): id = Column(Integer, primary_key=True) date_updated = Column(Da
是否可以使用外键引用并在 sqlalchemy 中的同一个表上有 oracle 分区? 这是在 __table_args__ 中将 oracle 分区定义为字典的方式 class SQLAlchemy
我正在尝试在基类中使用单个 CheckConstraint 创建基模型。当我将基类混合到 flask-sqlalchemy 模型中并尝试使用它时,我得到“无法将未命名的列添加到列集合”。 我试着用不同
我正在尝试使用flask、sqlalchemy 和flask_migrate ... 但是每次运行 manage.py migrate 时,alembic 总是将我的模型检测为新表。 我想我把 tab
在 SQLAlchemy 中,我已经阅读了如何在声明声明时组合来自不同 mixin 的 __table_args__。 Combining Table/Mapper Arguments from Mu
我有以下 SQLAlchemy 模型。已成功迁移至数据库: class MyClassA(db.Model, Timestamp): a_id = db.Column(db.Integer,
我是一名优秀的程序员,十分优秀!