Skip to content

Commit 85e5a74

Browse files
committed
fixing a bug with SchemaSnapshot if column types are changed
1 parent b31d26d commit 85e5a74

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

piccolo/apps/migrations/auto/schema_snapshot.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,23 @@ def get_snapshot(self) -> t.List[DiffableTable]:
7373
table.class_name
7474
)
7575
for alter_column in alter_columns:
76-
for column in table.columns:
76+
for index, column in enumerate(table.columns):
7777
if column._meta.name == alter_column.column_name:
7878
for key, value in alter_column.params.items():
7979
setattr(column._meta, key, value)
8080
column._meta.params.update({key: value})
8181

82+
# If the column type has changed, we need to update
83+
# it.
84+
if (
85+
alter_column.column_class
86+
!= alter_column.old_column_class
87+
):
88+
if alter_column.column_class is not None:
89+
new_column = alter_column.column_class()
90+
new_column._meta = column._meta
91+
table.columns[index] = new_column
92+
8293
###############################################################
8394

8495
for (

0 commit comments

Comments
 (0)