栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

sqlalchemy在多列中唯一

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

sqlalchemy在多列中唯一

从以下文档的摘录

Column

unique –为True时,指示此列包含唯一约束,或者,如果 index也
为True,则指示应使用唯一标志创建索引。要在约束/索引中指定多个列或指定一个显式名称,请显式使用
UniqueConstraint或Index构造。

由于这些属于表而不属于映射的类,因此可以在表定义中声明它们,或者如果使用声明性声明,例如

__table_args__

# version1: table definitionmytable = Table('mytable', meta,    # ...    Column('customer_id', Integer, ForeignKey('customers.customer_id')),    Column('location_pre', Unipre(10)),    UniqueConstraint('customer_id', 'location_pre', name='uix_1')    )# or the index, which will ensure uniqueness as wellIndex('myindex', mytable.c.customer_id, mytable.c.location_pre, unique=True)# version2: declarativeclass Location(base):    __tablename__ = 'locations'    id = Column(Integer, primary_key = True)    customer_id = Column(Integer, ForeignKey('customers.customer_id'), nullable=False)    location_pre = Column(Unipre(10), nullable=False)    __table_args__ = (UniqueConstraint('customer_id', 'location_pre', name='_customer_location_uc'),          )


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/514592.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号