If we have a database with DateTime property (datetime column) and we want to change the type to DateTimeOffset using migrations the following error with show up:
The object 'DF__Issues__CreatedT__15502E78' is dependent on column 'CreatedTime'.
ALTER TABLE ALTER COLUMN CreatedTime failed because one or more objects access this column.
The sql that we are trying to execute looks like this:
ALTER TABLE [dbo].[Issues] ALTER COLUMN [CreatedTime] [datetimeoffset](7) NOT NULL
However if one does the same operation using Designer in SQL Server Object Explorer (part of VS), the code they execute looks like this:
ALTER TABLE [dbo].[Issues] DROP CONSTRAINT [DF__Issues__CreatedT__15502E78];
ALTER TABLE [dbo].[Issues] ALTER COLUMN [CreatedTime] DATETIMEOFFSET (7) NOT NULL;
ALTER TABLE [dbo].[Issues] ADD DEFAULT ('1900-01-01T00:00:00.000') FOR [CreatedTime];
Pretty much dropping the default constraint, altering the database and then re-creating the default constraint. We should mimic that behavior if possible, otherwise Migrations experience is broken for this scenario.
The object 'DF__Issues__CreatedT__15502E78' is dependent on column 'CreatedTime'.
ALTER TABLE ALTER COLUMN CreatedTime failed because one or more objects access this column.
The sql that we are trying to execute looks like this:
ALTER TABLE [dbo].[Issues] ALTER COLUMN [CreatedTime] [datetimeoffset](7) NOT NULL
However if one does the same operation using Designer in SQL Server Object Explorer (part of VS), the code they execute looks like this:
ALTER TABLE [dbo].[Issues] DROP CONSTRAINT [DF__Issues__CreatedT__15502E78];
ALTER TABLE [dbo].[Issues] ALTER COLUMN [CreatedTime] DATETIMEOFFSET (7) NOT NULL;
ALTER TABLE [dbo].[Issues] ADD DEFAULT ('1900-01-01T00:00:00.000') FOR [CreatedTime];
Pretty much dropping the default constraint, altering the database and then re-creating the default constraint. We should mimic that behavior if possible, otherwise Migrations experience is broken for this scenario.