- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有以下 SQLAlchemy 模型。已成功迁移至数据库:
class MyClassA(db.Model, Timestamp):
a_id = db.Column(db.Integer, nullable=False, primary_key=True)
b_id = db.Column(db.Integer, db.ForeignKey(C.c_id), nullable=False)
d = db.Column(db.String(1024))
e_id = db.Column(db.Integer,
db.ForeignKey(e.e_id))
现在我想在第二个和第四个字段中添加唯一性约束。所以我将以下行添加到模型中:
__table_args__ = db.UniqueConstraint('b_id', 'e_id', name='unique_constraint_bid_eid')
但是现在当我尝试迁移它时,出现以下错误:
sqlalchemy.exc.ArgumentError: __table_args__ value must be a tuple, dict, or None
为什么会出现此错误?我该如何解决?我尝试将等式的右边放在括号中,但这并没有解决问题。
最佳答案
table_args 应该是元组、字典或 None,如错误代码所示。如果你把它变成一个元组,那么你必须把你的值放在括号里,最后还有一个逗号:
尝试:
__table_args__ = (db.UniqueConstraint('b_id', 'e_id', name='unique_constraint_bid_eid'), )
关于python - 为什么我收到 SQLAlchemy 错误 "__table_args__ value must be a tuple, dict, or None",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40521770/
我发现如果 __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,
我是一名优秀的程序员,十分优秀!