Skip to content

Commit ae0ad82

Browse files
committed
BUG24946101: Fix inline foreign key SQL generation.
This patch fixes the inline foreign key reference SQL generation. A non-existent variable name was used in place of the reference table name which gave rise to this issue. Tests cannot be verified because according to MySQL documentation: MySQL parses but ignores "inline REFERENCES specifications" (as defined in the SQL standard) where the references are defined as part of the column specification. MySQL accepts REFERENCES clauses only when specified as part of a separate FOREIGN KEY specification.
1 parent 9eb2056 commit ae0ad82

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

lib/mysqlx/statement.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,7 @@ def _col_definition(self):
12691269
defn = "{0} UNIQUE KEY".format(defn)
12701270
if self._ref_table and self._ref_fields:
12711271
ref_table = quote_multipart_identifier(parse_table_name(
1272-
self._default_schema, name))
1272+
self._default_schema, self._ref_table))
12731273
defn = "{0} REFERENCES {1} ({2})".format(defn, ref_table,
12741274
",".join(self._ref_fields))
12751275

tests/test_mysqlx_crud.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def test_create_table(self):
284284
.add_column(mysqlx.ColumnDef('release_year',
285285
mysqlx.ColumnType.YEAR, 4)) \
286286
.add_column(mysqlx.ColumnDef('language_id', mysqlx.ColumnType.INT) \
287-
.unsigned().not_null()) \
287+
.unsigned().not_null().foreign_key(table_a, 'language_id')) \
288288
.add_column(mysqlx.ColumnDef('original_language_id',
289289
mysqlx.ColumnType.INT).unsigned())\
290290
.add_column(mysqlx.ColumnDef('rental_duration',

0 commit comments

Comments
 (0)