Skip to content

Commit 96fc310

Browse files
committed
drop_column
1 parent 96ac87d commit 96fc310

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

sqlite_minutils/db.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,8 @@ def create_table(
955955
columns_to_drop = [
956956
column for column in existing_columns if column not in columns
957957
]
958+
if columns_to_drop:
959+
for col_name in columns_to_drop: table.drop_column(col_name)
958960
if missing_columns:
959961
for col_name, col_type in missing_columns.items():
960962
table.add_column(col_name, col_type)
@@ -987,7 +989,6 @@ def create_table(
987989
if should_transform:
988990
table.transform(
989991
types=columns,
990-
drop=columns_to_drop,
991992
column_order=column_order,
992993
not_null=not_null,
993994
defaults=defaults,
@@ -2124,6 +2125,22 @@ def create_index(
21242125
self.db.analyze(created_index_name)
21252126
return self
21262127

2128+
def drop_column(
2129+
self,
2130+
col_name: str
2131+
):
2132+
"""
2133+
Drop a column from this table.
2134+
2135+
:param col_name: Name of the new column
2136+
"""
2137+
sql = "ALTER TABLE [{table}] DROP COLUMN [{col_name}];".format(
2138+
table=self.name,
2139+
col_name=col_name,
2140+
)
2141+
self.db.execute(sql)
2142+
return self
2143+
21272144
def add_column(
21282145
self,
21292146
col_name: str,

0 commit comments

Comments
 (0)