我创建这个模型,我的代码第一个实体框架的一部分
public class NewUserRegistration
{
[Key]
public int NewUserRegistrationId { get; set; }
}
使用Update-Database -Verbose -Force
在包管理器ConsoleI命令该位在更新的过程中得到这个异常Applying automatic migration: 201211252223088_AutomaticMigration.
。ALTER TABLE [DBO] [NewUserRegistration] ADD [NewUserRegistrationId] [INT] NOT NULL IDENTITY System.Data.SqlClient.SqlException(0x80131904):表 'NewUserRegistration' 指定了多个标识列。 对于每个表一个标识列是允许的。 在System.Data.SqlClient.SqlConnection.OnError(SqlException异常,布尔breakConnection,动作
1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action
1个wrapCloseInAction)在System.Data.SqlClient.TdsParser .ThrowExceptionAndWarning(TdsParserStateObject stateObj,布尔callerHasConnectionLock,布尔asyncClose)在System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior,SqlCommand的cmdHandler,SqlDataReader的数据流,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj,布尔逻辑dataReady)在System.Data.SqlClient.SqlCommand。 RunExecuteNonQueryTds(字符串方法名,布尔异步,的Int32超时)在System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource1 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
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
1个migrationStatements)在System.Data.Entity的.Migrations.Infrastructure.MigratorBase.ExecuteStatements(IEnumerable的1 migrationStatements) at System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, XDocument targetModel, IEnumerable
在System.Data.Entity.Migrations 1个操作,布尔降级,布尔自动) .DbMigrator.AutoMigrate(字符串migrationId,的XDocument sourceModel,的XDocument targetModel,布尔降级)在System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.AutoMigrate(字符串migrationId,的XDocument sourceModel,的XDocument targetModel,布尔降级)在System.Data.Entity的.Migrations.DbMigrator.Upgrade(IEnumerable的1 pendingMigrations, String targetMigrationId, String lastMigrationId)
at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable1 pendingMigrations, String targetMigrationId, String lastMigrationId)
at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable1 pendingMigrations, String targetMigrationId, String lastMigrationId)
1个pendingMigrations,字符串targetMigrationId,字符串lastMigrationId)
at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable
在System.Data.Entity.Migrations.DbMigrator.Update(字符串targetMigration)在System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(字符串targetMigration)在System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.RunCore ()在System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()ClientConnectionId:表 'NewUserRegistration' 指定a39395da-5f2b-48e0-BDAC-b48d75a68c68多个标识列。 对于每个表一个标识列是允许的。
这里显然是只有一个指定的标识列。 那么,为什么是这样?
当我这样做,我得到也不例外。
public class NewUserRegistration
{
[Key]
public int Id { get; set; }
}
为什么是这样的话有什么想法?
编辑
我应该说,我改变了密钥的名称。 评论说,你不能仅仅做到这一点。 我怎样才能删除并重新创建?
它是最好从SQL删除数据库,然后只需运行Update-Database
再次命令?