public class NewUserRegistration { [Key] public int NewUserRegistrationId { get; set; } }
在Package Manger Console中使用Update-Database -Verbose -Force命令在更新的这一位期间获取此异常应用自动迁移:201211252223088_A自动迁移.
ALTER TABLE [dbo].[NewUserRegistration] ADD [NewUserRegistrationId]
[int] NOT NULL IDENTITY System.Data.sqlClient.sqlException
(0x80131904): Multiple identity columns specified for table
‘NewUserRegistration’. Only one identity column per table is allowed.
at System.Data.sqlClient.sqlConnection.OnError(sqlException exception,
Boolean breakConnection,Action1 wrapCloseInAction) at
1 wrapCloseInAction) at
System.Data.sqlClient.sqlInternalConnection.OnError(sqlException
exception,Boolean breakConnection,Action
System.Data.sqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
stateObj,Boolean callerHasConnectionLock,Boolean asyncClose) at
System.Data.sqlClient.TdsParser.TryRun(RunBehavior runBehavior,
sqlCommand cmdHandler,sqlDataReader dataStream,
BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject
stateObj,Boolean& dataReady) at
System.Data.sqlClient.sqlCommand.RunExecuteNonQueryTds(String
methodName,Boolean async,Int32 timeout) at
System.Data.sqlClient.sqlCommand.InternalExecuteNonQuery(TaskCompletionSource1
1
completion,String methodName,Boolean sendToPipe,Int32 timeout,
Boolean asyncWrite) at
System.Data.sqlClient.sqlCommand.ExecuteNonQuery() at
System.Data.Entity.Migrations.DbMigrator.Executesql(DbTransaction
transaction,MigrationStatement migrationStatement) at
System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Executesql(DbTransaction
transaction,MigrationStatement migrationStatement) at
System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable
migrationStatements) at
System.Data.Entity.Migrations.Infrastructure.MigratorBase.ExecuteStatements(IEnumerable1
1 operations,Boolean
migrationStatements) at
System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String
migrationId,XDocument targetModel,IEnumerable
downgrading,Boolean auto) at
System.Data.Entity.Migrations.DbMigrator.AutoMigrate(String
migrationId,XDocument sourceModel,Boolean
downgrading) at
System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.AutoMigrate(String
migrationId,Boolean
downgrading) at
System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable1
1
pendingMigrations,String targetMigrationId,String lastMigrationId)
at
System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable
pendingMigrations,String lastMigrationId)
at System.Data.Entity.Migrations.DbMigrator.Update(String
targetMigration) at
System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String
targetMigration) at
System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.RunCore()
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
ClientConnectionId:a39395da-5f2b-48e0-bdac-b48d75a68c68 Multiple
identity columns specified for table ‘NewUserRegistration’. Only one
identity column per table is allowed.
显然只有一个Identity Column被指定.那么为什么会这样呢?
当我这样做我也不例外.
public class NewUserRegistration { [Key] public int Id { get; set; } }
有什么想法为什么会这样呢?
编辑
解决方法
在这里,我确定首先订购Drop操作,然后再添加新的Key字段.
public partial class RenameKey : DbMigration { public override void Up() { DropPrimaryKey("dbo.GameSummary",new[] { "OldId" }); DropColumn("dbo.GameSummary","OldId"); AddColumn("dbo.GameSummary","Id",c => c.Int(nullable: false,identity: true)); AddPrimaryKey("dbo.GameSummary","Id"); }
希望能帮助你的情况.