[migration] only define variable if needed
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 09 Dec 2015 17:44:17 +0100
changeset 11003 53820b08a723
parent 11002 2973522a1924
child 11004 14ba505fb652
[migration] only define variable if needed
server/schema2sql.py
--- a/server/schema2sql.py	Thu Dec 17 17:14:08 2015 +0100
+++ b/server/schema2sql.py	Wed Dec 09 17:44:17 2015 +0100
@@ -219,11 +219,12 @@
     """return a sql type string corresponding to the constraints"""
     constraints = list(constraints)
     unique, sqltype = False, None
-    size_constrained_string = dbhelper.TYPE_MAPPING.get('SizeConstrainedString', 'varchar(%s)')
     if etype == 'String':
         for constraint in constraints:
             if isinstance(constraint, SizeConstraint):
                 if constraint.max is not None:
+                    size_constrained_string = dbhelper.TYPE_MAPPING.get(
+                        'SizeConstrainedString', 'varchar(%s)')
                     sqltype = size_constrained_string % constraint.max
             elif isinstance(constraint, UniqueConstraint):
                 unique = True