summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/mysql/base.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/dialects/mysql/base.py')
-rw-r--r--lib/sqlalchemy/dialects/mysql/base.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py
index d0f654fe2..8f5c0ac33 100644
--- a/lib/sqlalchemy/dialects/mysql/base.py
+++ b/lib/sqlalchemy/dialects/mysql/base.py
@@ -1451,6 +1451,20 @@ class MySQLCompiler(compiler.SQLCompiler):
class MySQLDDLCompiler(compiler.DDLCompiler):
def create_table_constraints(self, table):
"""Get table constraints."""
+
+ # For foreign keys, MySQL silently fails or drops other FK attributes
+ # if MATCH, DEFERRABLE, or INITIALLY are defined. Warn on 0.8, raise
+ # an error on 0.9
+ # https://dev.mysql.com/doc/refman/5.5/en/create-table-foreign-keys.html
+ for fk in table.foreign_keys:
+ for attr in ('match', 'deferrable', 'initially'):
+ if getattr(fk, attr) is not None:
+ raise exc.CompileError(
+ "MySQL does not support specifying MATCH, DEFERRABLE, "
+ "or INITIALLY on foreign keys, but a foreign key on "
+ "table '%s' defines at least one." % table.name
+ )
+
constraint_string = super(
MySQLDDLCompiler, self).create_table_constraints(table)