本文整理汇总了Python中sqlalchemy.test.schema.Table.append_constraint方法的典型用法代码示例。如果您正苦于以下问题:Python Table.append_constraint方法的具体用法?Python Table.append_constraint怎么用?Python Table.append_constraint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.test.schema.Table
的用法示例。
在下文中一共展示了Table.append_constraint方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_append_constraint_unique
# 需要导入模块: from sqlalchemy.test.schema import Table [as 别名]
# 或者: from sqlalchemy.test.schema.Table import append_constraint [as 别名]
def test_append_constraint_unique(self):
meta = MetaData()
users = Table('users', meta, Column('id', sa.Integer))
addresses = Table('addresses', meta, Column('id', sa.Integer), Column('user_id', sa.Integer))
fk = sa.ForeignKeyConstraint(['user_id'],[users.c.id])
addresses.append_constraint(fk)
addresses.append_constraint(fk)
assert len(addresses.c.user_id.foreign_keys) == 1
assert addresses.constraints == set([addresses.primary_key, fk])
示例2: test_fk_no_such_target_col_error
# 需要导入模块: from sqlalchemy.test.schema import Table [as 别名]
# 或者: from sqlalchemy.test.schema.Table import append_constraint [as 别名]
def test_fk_no_such_target_col_error(self):
meta = MetaData()
a = Table('a', meta, Column('a', Integer))
b = Table('b', meta, Column('b', Integer))
a.append_constraint(
ForeignKeyConstraint(['a'], ['b.x'])
)
def go():
list(a.c.a.foreign_keys)[0].column
assert_raises_message(
exc.NoReferencedColumnError,
"Could not create ForeignKey 'b.x' on "
"table 'a': table 'b' has no column named 'x'",
go
)
示例3: test_fk_copy
# 需要导入模块: from sqlalchemy.test.schema import Table [as 别名]
# 或者: from sqlalchemy.test.schema.Table import append_constraint [as 别名]
def test_fk_copy(self):
c1 = Column('foo', Integer)
c2 = Column('bar', Integer)
m = MetaData()
t1 = Table('t', m, c1, c2)
kw = dict(onupdate="X",
ondelete="Y", use_alter=True, name='f1',
deferrable="Z", initially="Q", link_to_name=True)
fk1 = ForeignKey(c1, **kw)
fk2 = ForeignKeyConstraint((c1,), (c2,), **kw)
t1.append_constraint(fk2)
fk1c = fk1.copy()
fk2c = fk2.copy()
for k in kw:
eq_(getattr(fk1c, k), kw[k])
eq_(getattr(fk2c, k), kw[k])