]> 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:20 +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]

doc/build/changelog/changelog_08.rst
doc/build/changelog/changelog_09.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 673a50a9a51cffcf674dcc80d385383aeec8dadb..c5ee84a7b6a2df643ece01f821e2b871acc7d74c 100644 (file)
@@ -6,6 +6,17 @@
 .. changelog::
     :version: 0.9.0
 
+    .. 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.  Also in 0.8.2.
+
     .. change::
         :tags: bug, ext, orm
         :tickets: 2730
index ad4650f6d75548fc52905de0983a91abd6c9c15b..03827edb7739eecafc3b93ed6292fb079f2012e0 100644 (file)
@@ -1567,6 +1567,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 728098d3abd28188b4adc8d98635b723d6dd02e8..2c459dead058bba4771ad49c6bae9c9be397cf46 100644 (file)
@@ -82,6 +82,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'