Unable to add primary key constraint to nullable identity column

Malthe
Valued Contributor II

While we can in fact define a primary key during table creation for an identity column that's nullable (i.e., not constrained using NOT NULL), it's not possible to add such a primary key constraint after the table has been created.

We get an error message:
> Cannot create the primary key `my_table_pk` because its child column(s) `id` is nullable. Please change the column nullability and retry.

But it's not possible to change the nullability of an identity column:
> ALTER TABLE ALTER COLUMN is not supported for IDENTITY columns.

I'm not sure if logically speaking this is a bug, but it's a bit of an unfortunate situation if you want to move to a table setup with constraints and haven't created the identity columns initially with a nullability constraint.