t = metadata.tables[key]
for elem in constraint.elements:
colname = elem._get_colspec().split(".")[-1]
- if not t.c.contains_column(colname):
+ if colname not in t.c:
t.append_column(Column(colname, sqltypes.NULLTYPE))
else:
Table(
--- /dev/null
+.. change::
+ :tags: bug, batch
+
+ Fixed issue where columns in a foreign-key referenced table would be
+ replaced with null-type columns during a batch operation; while this did
+ not generally have any side effects, it could theoretically impact a batch
+ operation that also targets that table directly and also would interfere
+ with future changes to the ``.append_column()`` method to disallow implicit
+ replacement of columns.
\ No newline at end of file
from alembic.testing import config
from alembic.testing import eq_
from alembic.testing import exclusions
+from alembic.testing import is_
from alembic.testing import mock
from alembic.testing import TestBase
from alembic.testing.fixtures import op_fixture
schema="foo_schema",
)
+ def test_do_not_add_existing_columns_columns(self):
+ impl = self._multi_fk_fixture()
+ meta = impl.table.metadata
+
+ cid = Column("id", Integer())
+ user = Table("user", meta, cid)
+
+ fk = [
+ c
+ for c in impl.unnamed_constraints
+ if isinstance(c, ForeignKeyConstraint)
+ ]
+ impl._setup_referent(meta, fk[0])
+ is_(user.c.id, cid)
+
def test_drop_col(self):
impl = self._simple_fixture()
impl.drop_column("tname", column("x"))