]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
The ``deferrable`` keyword argument on :class:`.ForeignKey` and
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 3 Jun 2013 22:33:20 +0000 (18:33 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 3 Jun 2013 22:33:57 +0000 (18:33 -0400)
:class:`.ForeignKeyConstraint` will not render the ``DEFERRABLE`` keyword
on the MySQL dialect.  For a long time we left this in place because
a non-deferrable foreign key would act very differently than a deferrable
one, but some environments just disable FKs on MySQL, so we'll be less
opinionated here. [ticket:2721]

Conflicts:
doc/build/changelog/changelog_09.rst

doc/build/changelog/changelog_08.rst
lib/sqlalchemy/dialects/mysql/base.py
test/dialect/test_mysql.py

index 94ada9ac59f87876cf2705ed003f07d5ee3ca78b..82e65272b7bb690b31384b51eae7ef5a88ba8950 100644 (file)
@@ -6,6 +6,17 @@
 .. changelog::
     :version: 0.8.2
 
+    .. change::
+        :tags: bug, mysql
+        :tickets: 2721
+
+        The ``deferrable`` keyword argument on :class:`.ForeignKey` and
+        :class:`.ForeignKeyConstraint` will not render the ``DEFERRABLE`` keyword
+        on the MySQL dialect.  For a long time we left this in place because
+        a non-deferrable foreign key would act very differently than a deferrable
+        one, but some environments just disable FKs on MySQL, so we'll be less
+        opinionated here.
+
     .. change::
         :tags: bug, ext, orm
         :tickets: 2730
index 076fa25177a6091c9ef6d61d85f1dfe6349b313d..1ae10aa03ca8dfa2aeab2db32a257eab026a1c4b 100644 (file)
@@ -1571,6 +1571,8 @@ class MySQLDDLCompiler(compiler.DDLCompiler):
                     (self.preparer.format_table(constraint.table),
                     qual, const)
 
+    def define_constraint_deferrability(self, constraint):
+        return ""
 
 class MySQLTypeCompiler(compiler.GenericTypeCompiler):
     def _extend_numeric(self, type_, spec):
index f89b0b229ef041c9553df64e28d164476522e23a..541f4cd4852148743faa53b53d3594cd0a019234 100644 (file)
@@ -81,6 +81,19 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
             "PRIMARY KEY (data) USING btree)",
             dialect=mysql.dialect())
 
+    def test_skip_deferrable_kw(self):
+        m = MetaData()
+        t1 = Table('t1', m, Column('id', Integer, primary_key=True))
+        t2 = Table('t2', m, Column('id', Integer,
+                        ForeignKey('t1.id', deferrable=True),
+                            primary_key=True))
+
+        self.assert_compile(
+            schema.CreateTable(t2),
+            "CREATE TABLE t2 (id INTEGER NOT NULL, "
+            "PRIMARY KEY (id), FOREIGN KEY(id) REFERENCES t1 (id))"
+        )
+
 class DialectTest(fixtures.TestBase):
     __only_on__ = 'mysql'