Automatic migration was not applied because it would result in data loss
广告:
PM> update-database -Verbose
Using StartUp project 'TopWin.Etone.Web'.
Using NuGet project 'TopWin.Etone.Domain'.
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Target database is: 'Yunyou' (DataSource: .\sql2008, Provider: System.Data.SqlClient, Origin: Configuration).
No pending code-based migrations.
Applying automatic migration: 201307170115022_AutomaticMigration.
Automatic migration was not applied because it would result in data loss.
解决方法:提示“Automatic migration was not applied because it would result in data loss”(不能自动迁移,会导致数据丢失) ,则在Update-Database 后面加 -Force参数即可。注意,这样并不会引起数据丢失。
成功后提示:
PM> update-database -Force -Verbose
Using StartUp project 'TopWin.Etone.Web'.
Using NuGet project 'TopWin.Etone.Domain'.
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Target database is: 'Yunyou' (DataSource: .\sql2008, Provider: System.Data.SqlClient, Origin: Configuration).
No pending code-based migrations.
Applying automatic migration: 201307170118213_AutomaticMigration.
ALTER TABLE [dbo].[Customer] ADD [CustomerName2] [nvarchar](max)
DECLARE @var0 nvarchar(128)
SELECT @var0 = name
FROM sys.default_constraints
WHERE parent_object_id = object_id(N'dbo.Customer')
AND col_name(parent_object_id, parent_column_id) = 'CustomerName1';
IF @var0 IS NOT NULL
EXECUTE('ALTER TABLE [dbo].[Customer] DROP CONSTRAINT ' + @var0)
ALTER TABLE [dbo].[Customer] DROP COLUMN [CustomerName1]
[Inserting migration history record]
Running Seed method.
PM>
广告: