Append a :class:`_schema.Column` to this :class:`_schema.Table`. The "key" of the newly added :class:`_schema.Column`, i.e. the value of its ``.key`` attribute, will then be available in the ``.c`` collection of this :class:`_schema.Table`, and the column definition
(
self, column: ColumnClause[Any], replace_existing: bool = False
)
| 1207 | self._extra_dependencies.add(table) |
| 1208 | |
| 1209 | def append_column( |
| 1210 | self, column: ColumnClause[Any], replace_existing: bool = False |
| 1211 | ) -> None: |
| 1212 | """Append a :class:`_schema.Column` to this :class:`_schema.Table`. |
| 1213 | |
| 1214 | The "key" of the newly added :class:`_schema.Column`, i.e. the |
| 1215 | value of its ``.key`` attribute, will then be available |
| 1216 | in the ``.c`` collection of this :class:`_schema.Table`, and the |
| 1217 | column definition will be included in any CREATE TABLE, SELECT, |
| 1218 | UPDATE, etc. statements generated from this :class:`_schema.Table` |
| 1219 | construct. |
| 1220 | |
| 1221 | Note that this does **not** change the definition of the table |
| 1222 | as it exists within any underlying database, assuming that |
| 1223 | table has already been created in the database. Relational |
| 1224 | databases support the addition of columns to existing tables |
| 1225 | using the SQL ALTER command, which would need to be |
| 1226 | emitted for an already-existing table that doesn't contain |
| 1227 | the newly added column. |
| 1228 | |
| 1229 | :param replace_existing: When ``True``, allows replacing existing |
| 1230 | columns. When ``False``, the default, an warning will be raised |
| 1231 | if a column with the same ``.key`` already exists. A future |
| 1232 | version of sqlalchemy will instead rise a warning. |
| 1233 | |
| 1234 | .. versionadded:: 1.4.0 |
| 1235 | """ |
| 1236 | |
| 1237 | try: |
| 1238 | column._set_parent_with_dispatch( |
| 1239 | self, |
| 1240 | allow_replacements=replace_existing, |
| 1241 | all_names={c.name: c for c in self.c}, |
| 1242 | ) |
| 1243 | except exc.DuplicateColumnError as de: |
| 1244 | raise exc.DuplicateColumnError( |
| 1245 | f"{de.args[0]} Specify replace_existing=True to " |
| 1246 | "Table.append_column() to replace an " |
| 1247 | "existing column." |
| 1248 | ) from de |
| 1249 | |
| 1250 | def append_constraint(self, constraint: Union[Index, Constraint]) -> None: |
| 1251 | """Append a :class:`_schema.Constraint` to this |