diff options
| author | Derek Harland <derek.harland@finq.co.nz> | 2012-12-04 13:56:48 +1300 |
|---|---|---|
| committer | Derek Harland <derek.harland@finq.co.nz> | 2012-12-04 13:56:48 +1300 |
| commit | ab7103b7b5d8d7f3f1b21970f368c8c60eca595b (patch) | |
| tree | 598f0b38fbf79b9fd2042b815002c65bf522ae74 | |
| parent | 92535b4b575874a6c0f0392cab46300fe59107ee (diff) | |
| download | sqlalchemy-ab7103b7b5d8d7f3f1b21970f368c8c60eca595b.tar.gz | |
Allow the MSSQL dialect to support identity columns that are not part of the primary key
| -rw-r--r-- | lib/sqlalchemy/dialects/mssql/base.py | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index f55ae4644..0f862f10b 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: |
