File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed
Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -415,7 +415,7 @@ async def _run_alter_columns(self, backwards=False):
415415 column ._meta ._name = column_name
416416 await _Table .drop_index ([column ]).run ()
417417 await _Table .create_index (
418- [column ], method = index_method
418+ [column ], method = index_method , if_not_exists = True
419419 ).run ()
420420 else :
421421 # If the index value has changed, then we are either
@@ -427,7 +427,9 @@ async def _run_alter_columns(self, backwards=False):
427427 kwargs = (
428428 {"method" : index_method } if index_method else {}
429429 )
430- await _Table .create_index ([column ], ** kwargs ).run ()
430+ await _Table .create_index (
431+ [column ], if_not_exists = True , ** kwargs
432+ ).run ()
431433 else :
432434 await _Table .drop_index ([column ]).run ()
433435
Original file line number Diff line number Diff line change @@ -623,14 +623,20 @@ def create_index(
623623 cls ,
624624 columns : t .List [t .Union [Column , str ]],
625625 method : IndexMethod = IndexMethod .btree ,
626+ if_not_exists : bool = False ,
626627 ) -> CreateIndex :
627628 """
628629 Create a table index. If multiple columns are specified, this refers
629630 to a multicolumn index, rather than multiple single column indexes.
630631
631632 await Band.create_index([Band.name]).run()
632633 """
633- return CreateIndex (table = cls , columns = columns , method = method )
634+ return CreateIndex (
635+ table = cls ,
636+ columns = columns ,
637+ method = method ,
638+ if_not_exists = if_not_exists ,
639+ )
634640
635641 @classmethod
636642 def drop_index (
You can’t perform that action at this time.
0 commit comments