contraint name for column level constraints

Issue #2305 resolved
Mike Bayer repo owner created an issue

need to put this only on those DBs which support it (or override those that don't support it).

So far PG and SQLite seem to support it, MySQL does not:

--- a/lib/sqlalchemy/sql/compiler.py    Thu Oct 20 15:00:17 2011 -0400
+++ b/lib/sqlalchemy/sql/compiler.py    Fri Oct 21 20:07:28 2011 -0400
@@ -1403,7 +1403,11 @@
         return text

     def visit_column_check_constraint(self, constraint):
-        text = "CHECK (%s)" % constraint.sqltext
+        text = ""
+        if constraint.name is not None:
+            text += "CONSTRAINT %s " % \
+                        self.preparer.format_constraint(constraint)
+        text += "CHECK (%s)" % constraint.sqltext
         text += self.define_constraint_deferrability(constraint)
         return text

Comments (2)

  1. Log in to comment