本文整理汇总了Python中alembic.operations.Operations._foreign_key_constraint方法的典型用法代码示例。如果您正苦于以下问题:Python Operations._foreign_key_constraint方法的具体用法?Python Operations._foreign_key_constraint怎么用?Python Operations._foreign_key_constraint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类alembic.operations.Operations
的用法示例。
在下文中一共展示了Operations._foreign_key_constraint方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BatchApplyTest
# 需要导入模块: from alembic.operations import Operations [as 别名]
# 或者: from alembic.operations.Operations import _foreign_key_constraint [as 别名]
#.........这里部分代码省略.........
new_table = self._assert_impl(
impl, colnames=['x', 'y'], ddl_not_contains="PRIMARY KEY")
assert 'y' in new_table.c
assert 'id' not in new_table.c
assert not new_table.primary_key
def test_drop_col_remove_fk(self):
impl = self._fk_fixture()
impl.drop_column('tname', column('user_id'))
new_table = self._assert_impl(
impl, colnames=['id', 'email'], ddl_not_contains="FOREIGN KEY")
assert 'user_id' not in new_table.c
assert not new_table.foreign_keys
def test_drop_col_retain_fk(self):
impl = self._fk_fixture()
impl.drop_column('tname', column('email'))
new_table = self._assert_impl(
impl, colnames=['id', 'user_id'],
ddl_contains='FOREIGN KEY(user_id) REFERENCES "user" (id)')
assert 'email' not in new_table.c
assert new_table.c.user_id.foreign_keys
def test_drop_col_retain_fk_selfref(self):
impl = self._selfref_fk_fixture()
impl.drop_column('tname', column('data'))
new_table = self._assert_impl(impl, colnames=['id', 'parent_id'])
assert 'data' not in new_table.c
assert new_table.c.parent_id.foreign_keys
def test_add_fk(self):
impl = self._simple_fixture()
impl.add_column('tname', Column('user_id', Integer))
fk = self.op._foreign_key_constraint(
'fk1', 'tname', 'user',
['user_id'], ['id'])
impl.add_constraint(fk)
new_table = self._assert_impl(
impl, colnames=['id', 'x', 'y', 'user_id'],
ddl_contains='CONSTRAINT fk1 FOREIGN KEY(user_id) '
'REFERENCES "user" (id)')
eq_(
list(new_table.c.user_id.foreign_keys)[0]._get_colspec(),
'user.id'
)
def test_drop_fk(self):
impl = self._named_fk_fixture()
fk = ForeignKeyConstraint([], [], name='ufk')
impl.drop_constraint(fk)
new_table = self._assert_impl(
impl, colnames=['id', 'email', 'user_id'],
ddl_not_contains="CONSTRANT fk1")
eq_(
list(new_table.foreign_keys),
[]
)
def test_add_uq(self):
impl = self._simple_fixture()
uq = self.op._unique_constraint(
'uq1', 'tname', ['y']
)
impl.add_constraint(uq)
self._assert_impl(
示例2: BatchApplyTest
# 需要导入模块: from alembic.operations import Operations [as 别名]
# 或者: from alembic.operations.Operations import _foreign_key_constraint [as 别名]
#.........这里部分代码省略.........
new_table = self._assert_impl(
impl, colnames=['x', 'y'], ddl_not_contains="PRIMARY KEY")
assert 'y' in new_table.c
assert 'id' not in new_table.c
assert not new_table.primary_key
def test_drop_col_remove_fk(self):
impl = self._fk_fixture()
impl.drop_column('tname', column('user_id'))
new_table = self._assert_impl(
impl, colnames=['id', 'email'], ddl_not_contains="FOREIGN KEY")
assert 'user_id' not in new_table.c
assert not new_table.foreign_keys
def test_drop_col_retain_fk(self):
impl = self._fk_fixture()
impl.drop_column('tname', column('email'))
new_table = self._assert_impl(
impl, colnames=['id', 'user_id'],
ddl_contains='FOREIGN KEY(user_id) REFERENCES "user" (id)')
assert 'email' not in new_table.c
assert new_table.c.user_id.foreign_keys
def test_drop_col_retain_fk_selfref(self):
impl = self._selfref_fk_fixture()
impl.drop_column('tname', column('data'))
new_table = self._assert_impl(impl, colnames=['id', 'parent_id'])
assert 'data' not in new_table.c
assert new_table.c.parent_id.foreign_keys
def test_add_fk(self):
impl = self._simple_fixture()
impl.add_column('tname', Column('user_id', Integer))
fk = self.op._foreign_key_constraint(
'fk1', 'tname', 'user',
['user_id'], ['id'])
impl.add_constraint(fk)
new_table = self._assert_impl(
impl, colnames=['id', 'x', 'y', 'user_id'],
ddl_contains='CONSTRAINT fk1 FOREIGN KEY(user_id) '
'REFERENCES "user" (id)')
eq_(
list(new_table.c.user_id.foreign_keys)[0]._get_colspec(),
'user.id'
)
def test_drop_fk(self):
impl = self._named_fk_fixture()
fk = ForeignKeyConstraint([], [], name='ufk')
impl.drop_constraint(fk)
new_table = self._assert_impl(
impl, colnames=['id', 'email', 'user_id'],
ddl_not_contains="CONSTRANT fk1")
eq_(
list(new_table.foreign_keys),
[]
)
def test_add_uq(self):
impl = self._simple_fixture()
uq = self.op._unique_constraint(
'uq1', 'tname', ['y']
)
impl.add_constraint(uq)
self._assert_impl(