本文整理汇总了Python中test.lib.schema.Table.append_constraint方法的典型用法代码示例。如果您正苦于以下问题:Python Table.append_constraint方法的具体用法?Python Table.append_constraint怎么用?Python Table.append_constraint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类test.lib.schema.Table
的用法示例。
在下文中一共展示了Table.append_constraint方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_fk_no_such_target_col_error
# 需要导入模块: from test.lib.schema import Table [as 别名]
# 或者: from test.lib.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
)
示例2: test_fk_copy
# 需要导入模块: from test.lib.schema import Table [as 别名]
# 或者: from test.lib.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])