diff options
author | ijl <uijllji@gmail.com> | 2013-10-15 17:06:42 -0400 |
---|---|---|
committer | ijl <uijllji@gmail.com> | 2013-10-15 19:53:19 -0400 |
commit | 02849148d7a4f02328c7565953aa61e2378fc986 (patch) | |
tree | 5aaf348983b6dafa4121ef8eeb48465cc6af4e80 /lib/sqlalchemy | |
parent | 92534dc8f30d173deaa1221a6872fd9b7ceae325 (diff) | |
download | sqlalchemy-pr/38.tar.gz |
MySQL dialect throws CompileError when unsupported foreign key options are specified, as MySQL silently ignores them [ticket 2841]pr/38
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r-- | lib/sqlalchemy/dialects/mysql/base.py | 14 |
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) |