summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorijl <uijllji@gmail.com>2013-10-15 17:06:42 -0400
committerijl <uijllji@gmail.com>2013-10-15 17:06:42 -0400
commit98e791836c51fd0a9452141047b539af5f0f95bd (patch)
tree6f2319238dc3dbc376e373218604dfb60710b426 /lib/sqlalchemy
parent92534dc8f30d173deaa1221a6872fd9b7ceae325 (diff)
downloadsqlalchemy-pr/36.tar.gz
#2841: MySQL doesn't support MATCH, INITIALLY, or DEFERREDpr/36
Diffstat (limited to 'lib/sqlalchemy')
-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..60519b798 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. So let's raise an
+ # error here.
+ # https://dev.mysql.com/doc/refman/5.5/en/create-table-foreign-keys.html
+ for attr in ('match', 'deferrable', 'initially'):
+ for fk in table.foreign_keys:
+ 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)