From: Derek Harland Date: Tue, 4 Dec 2012 00:56:48 +0000 (+1300) Subject: Allow the MSSQL dialect to support identity columns that are not part of the primary key X-Git-Tag: rel_0_8_0~34^2~1^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ab7103b7b5d8d7f3f1b21970f368c8c60eca595b;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Allow the MSSQL dialect to support identity columns that are not part of the primary key --- diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index f55ae46444..0f862f10bb 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -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: