运行Update-
Database -Verbose时出现以下错误:
Using StartUp project ‘WebApplication’. Using NuGet project ‘WebApplication’. Specify the ‘-Verbose’ flag to view the SQL statements being applied to the target database. Target database is: ‘Frappuccino’ (DataSource: (Localdb)v11.0,Provider: System.Data.SqlClient,Origin: Configuration). No pending explicit migrations. Applying automatic migration: 201402032027563_AutomaticMigration. ALTER TABLE [dbo].[Clients] ALTER COLUMN [ID] [int] NOT NULL System.Data.SqlClient.SqlException (0x80131904): The object ‘PK_dbo.Clients’ is dependent on column ‘ID’. The object ‘FK_dbo.Users_dbo.Clients_Client_ID’ is dependent on column ‘ID’. ALTER TABLE ALTER COLUMN ID failed because one or more objects access this column. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection,Action1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception,Boolean breakConnection,Action 1 wrapCloseInAction) at 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,Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource1 completion,String methodName,Boolean sendToPipe, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at System.Data.Entity.Infrastructure.Interception.InternalDispatcher 1.Dispatch[TInterceptionContext,TResult](Func1 operation,TInterceptionContext interceptionContext,Action 1 executing,Action1 executed) at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.NonQuery(DbCommand command,DbCommandInterceptionContext interceptionContext) at System.Data.Entity.Internal.InterceptableDbCommand.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.ExecuteStatementsInternal(IEnumerable 1 migrationStatements,DbConnection connection) at System.Data.Entity.Migrations.DbMigrator.<>c_DisplayClass32.b_2e() at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c_DisplayClass1.b_0() at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func1 operation) at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation) at System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable 1 migrationStatements) at System.Data.Entity.Migrations.Infrastructure.MigratorBase.ExecuteStatements(IEnumerable1 migrationStatements) at System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId,XDocument targetModel,IEnumerable 1 operations, IEnumerable1 systemOperations,Boolean 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(IEnumerable 1 pendingMigrations,String targetMigrationId,String lastMigrationId) at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1 pendingMigrations,String lastMigrationId) at System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String targetMigration) at System.Data.Entity.Migrations.DbMigrator.<>c_DisplayClassc.b_b() at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase) at System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase) 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.Run() at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate) at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate) at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner) at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration,Boolean force) at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c_DisplayClass2.<.ctor>b_0() at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command) ClientConnectionId:9854ba62-772c-4ba6-b185-ecae993e065f The object ‘PK_dbo.Clients’ is dependent on column ‘ID’. The object ‘FK_dbo.Users_dbo.Clients_Client_ID’ is dependent on column ‘ID’. ALTER TABLE ALTER COLUMN ID failed because one or more objects access this column.
在此之前我做的是将ID变量从我的Code-First Model类从Int16更改为Int32.
有什么帮助吗?
解决方法
看起来数据库无法更改/删除ID列,因为另一个表具有引用ID列的外键.如果删除引用,更新列,然后重新添加引用,你应该好好去…
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|