1. Michael Manfre
  2. django-mssql
  3. Issues


Issue #34 invalid

AutoFields named id are not getting primary_key=True

Mark Jones
created an issue
This is the TSQL to create the column. USE [Aud] GO /****** Object: Table [dbo].[dtproperties] Script Date: 08/16/2013 16:09:41 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[dtproperties]( [id] [int] IDENTITY(1,1) NOT NULL, [objectid] [int] NULL, [property] [varchar](64) NOT NULL, [value] [varchar](255) NULL, [uvalue] [nvarchar](255) NULL, [lvalue] [image] NULL, [version] [int] NOT NULL, CONSTRAINT [pk_dtproperties] PRIMARY KEY CLUSTERED ( [id] ASC, [property] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO SET ANSI_PADDING OFF GO ALTER TABLE [dbo].[dtproperties] ADD DEFAULT (0) FOR [version] GO

Comments (6)

  1. Mark Jones reporter

    I'm not trying to create multi-column primary keys. Normally you don't express the id column in a model, when inspecting and you run across one of these, it should get the primary=True added to the arguments, or it should be dropped from the list of fields. In my case the ID field is all caps, but the converted field is lowercase 'id'. Since the id field isn't created if one is present, if the id field exists and is an autoincrement field, it should get the Primary=True arguments so that it becomes the primary key on the model. Otherwise you have to do it by hand. And if you have 100 models, that's a lot of additional work.

  2. Mark Jones reporter

    NM, I see the MSSQL is trying to create a composite key now. Looks like Bit Bucket does not allow you to delete a comment once it is made though.

    Would be nice if it would put Primary=True on there and just drop the other part, but maybe it is better to make the user explicitly do that.

  3. Michael Manfre repo owner

    The multi-column primary key is in the create.sql you attached.

        [id] ASC,
        [property] ASC
    ) ...

    If you're experiencing this issue with Django's inspectdb management command for tables with a single column primary key, then you should open an issue with the Django Framework. https://code.djangoproject.com/

  4. Log in to comment