summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorijl <uijllji@gmail.com>2013-10-15 19:46:07 -0400
committerijl <uijllji@gmail.com>2013-10-15 19:55:07 -0400
commit245b3facec6c1d8cebf40704d09b974113f7b601 (patch)
treeab46e133e02ade0706f29e08fa07dbc8ad5ee9d4
parent92534dc8f30d173deaa1221a6872fd9b7ceae325 (diff)
downloadsqlalchemy-pr/37.tar.gz
MySQL dialect warns about unsupported foreign key options [ticket 2841]pr/37
-rw-r--r--lib/sqlalchemy/dialects/mysql/base.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py
index d0f654fe2..3252c4fcb 100644
--- a/lib/sqlalchemy/dialects/mysql/base.py
+++ b/lib/sqlalchemy/dialects/mysql/base.py
@@ -1451,6 +1451,29 @@ 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
+ warned = False
+ for fk in table.foreign_keys:
+ if warned is True:
+ break
+ for attr in ('match', 'deferrable', 'initially'):
+ if getattr(fk, attr) is not None:
+ util.warn(
+ "MySQL silently ignores the options MATCH, DEFERRABLE, "
+ "or INITIALLY on foreign keys, and the options ON UPDATE "
+ "and ON DELETE when MATCH is used, but table '%s' uses "
+ "at least one such option. Your MySQL schema probably "
+ "differs from your definition. This will throw a "
+ "CompileError on SQLAlchemy 0.9." % table.name
+ )
+ warned = True
+ break
+
+
constraint_string = super(
MySQLDDLCompiler, self).create_table_constraints(table)