@@ -419,14 +419,17 @@ def _build_create_table_sql(self, table_name: str) -> str:
419
419
# check if the index name collides with any table name
420
420
self ._mysql_cur_dict .execute (
421
421
"""
422
- SELECT COUNT(*)
422
+ SELECT COUNT(*) AS `count`
423
423
FROM information_schema.TABLES
424
424
WHERE TABLE_SCHEMA = %s
425
425
AND TABLE_NAME = %s
426
426
""" ,
427
427
(self ._mysql_database , index_name ),
428
428
)
429
- index_name_collision : t .Optional [t .Dict [str , ToPythonOutputTypes ]] = self ._mysql_cur_dict .fetchone ()
429
+ collision : t .Optional [t .Dict [str , ToPythonOutputTypes ]] = self ._mysql_cur_dict .fetchone ()
430
+ table_collisions : int = 0
431
+ if collision is not None :
432
+ table_collisions = int (collision ["count" ]) # type: ignore[arg-type]
430
433
431
434
columns : str = ""
432
435
if isinstance (index ["columns" ], bytes ):
@@ -443,7 +446,7 @@ def _build_create_table_sql(self, table_name: str) -> str:
443
446
indices += """CREATE {unique} INDEX IF NOT EXISTS "{name}" ON "{table}" ({columns});""" .format (
444
447
unique = "UNIQUE" if index ["unique" ] in {1 , "1" } else "" ,
445
448
name = f"{ table_name } _{ index_name } "
446
- if (index_name_collision is not None or self ._prefix_indices )
449
+ if (table_collisions > 0 or self ._prefix_indices )
447
450
else index_name ,
448
451
table = table_name ,
449
452
columns = ", " .join (f'"{ column } "' for column in columns .split ("," )),
0 commit comments