Fixed bug with add_foreign_key against columns with spaces, closes #238

This commit is contained in:
Simon Willison 2021-02-25 08:53:53 -08:00
commit a76e3b33ac
4 changed files with 32 additions and 17 deletions

View file

@ -593,7 +593,7 @@ class Database:
table_sql = {}
for table, column, other_table, other_column in foreign_keys_to_create:
old_sql = table_sql.get(table, self[table].schema)
extra_sql = ",\n FOREIGN KEY({column}) REFERENCES {other_table}({other_column})\n".format(
extra_sql = ",\n FOREIGN KEY([{column}]) REFERENCES [{other_table}]([{other_column}])\n".format(
column=column, other_table=other_table, other_column=other_column
)
# Stick that bit in at the very end just before the closing ')'