我正在使用Azure /发布SQL部署。我有一个DACPAC文件要部署,但我(1)更改了列数据类型,(2)删除了已经有数据的表上的某些列,(3)并添加了一些FK列。但是因为已经有了生产数据,所以部署失败。在这些情况下应采取什么解决方案? SQL DEPLOY image
The column [dbo].[TableSample][ColumnSample] is being dropped, data loss could occur.
The type for column Description in table [dbo].[Table2] is currently NVARCHAR (1024) NULL but is being changed to NVARCHAR (100) NOT NULL. Data loss could occur.
The type for column Id in table [dbo].[Table3] is currently UNIQUEIDENTIFIER NOT NULL but is being changed to INT NOT NULL.
There is no implicit or explicit conversion. ***
The column [sampleColumnId] on table [dbo].[Table4] must be added
, but the column has no default value and does not allow NULL values. If the table contains data, the ALTER script will not work.
To avoid this issue you must either: add a default value to the column, mark it as allowing NULL values, or enable the generation of smart-defaults as a deployment option.
答案 0 :(得分:1)
您可以通过在发布选项中使用“允许数据丢失”选项来关闭“数据丢失”警告。这只是警告您删除列或将数据长度减小。
您对“ Table3”的更改将无法与保留数据一起使用。 GUID将不适合在INT列中。您可能需要查看删除/重新创建表或将当前ID列重命名为其他名称(可能是OldId),并添加一个新的INT类型的ID,可能带有Identity(1,1)。
但是最后一列-您试图将没有默认值的NOT NULL列添加到现有表中。要么允许NULL,要么在列上放置一个命名的默认值,以便可以添加该列。