]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Allow the MSSQL dialect to support identity columns that are not part of the primary key
authorDerek Harland <derek.harland@finq.co.nz>
Tue, 4 Dec 2012 00:56:48 +0000 (13:56 +1300)
committerDerek Harland <derek.harland@finq.co.nz>
Tue, 4 Dec 2012 00:56:48 +0000 (13:56 +1300)
lib/sqlalchemy/dialects/mssql/base.py

index f55ae464444f9b266c9cf67d71abf5a0df181a19..0f862f10bb4b802606e9466baf68a2ee3b921a6f 100644 (file)
@@ -1028,18 +1028,16 @@ class MSDDLCompiler(compiler.DDLCompiler):
                             "mssql requires Table-bound columns "
                             "in order to generate DDL")
 
-        seq_col = column.table._autoincrement_column
-
-        # install a IDENTITY Sequence if we have an implicit IDENTITY column
-        if seq_col is column:
-            sequence = isinstance(column.default, sa_schema.Sequence) and \
-                            column.default
-            if sequence:
-                start, increment = sequence.start or 1, \
-                                    sequence.increment or 1
+        # install an IDENTITY Sequence if we either a sequence or an implicit IDENTITY column
+        if isinstance(column.default, sa_schema.Sequence):
+            if column.default.start == 0:
+                start = 0
             else:
-                start, increment = 1, 1
-            colspec += " IDENTITY(%s,%s)" % (start, increment)
+                start = column.default.start or 1
+
+            colspec += " IDENTITY(%s,%s)" % (start, column.default.increment or 1)
+        elif column is column.table._autoincrement_column:
+            colspec += " IDENTITY(1,1)"
         else:
             default = self.get_column_default_string(column)
             if default is not None: