Skip to content

Commit 596ee80

Browse files
authored
🐛 fix #76 prevent AUTO_INCREMENT-ing fields from having a DEFAULT (#77)
1 parent 3f4cfcc commit 596ee80

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

sqlite3_to_mysql/transporter.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,15 +326,17 @@ def _create_table(self, table_name: str, transfer_rowid: bool = False) -> None:
326326
if "hidden" in column and column["hidden"] == 1:
327327
continue
328328

329+
auto_increment: bool = (
330+
column["pk"] > 0 and column_type.startswith(("INT", "BIGINT")) and not compound_primary_key
331+
)
332+
329333
sql += " `{name}` {type} {notnull} {default} {auto_increment}, ".format(
330334
name=mysql_safe_name,
331335
type=column_type,
332336
notnull="NOT NULL" if column["notnull"] or column["pk"] else "NULL",
333-
auto_increment="AUTO_INCREMENT"
334-
if column["pk"] > 0 and column_type.startswith(("INT", "BIGINT")) and not compound_primary_key
335-
else "",
337+
auto_increment="AUTO_INCREMENT" if auto_increment else "",
336338
default="DEFAULT " + column["dflt_value"]
337-
if column["dflt_value"] and column_type not in MYSQL_COLUMN_TYPES_WITHOUT_DEFAULT
339+
if column["dflt_value"] and column_type not in MYSQL_COLUMN_TYPES_WITHOUT_DEFAULT and not auto_increment
338340
else "",
339341
)
340342

0 commit comments

Comments
 (0)