错误在运行更新,数据库 [英] Error while running Update-Database
问题描述
我运行时得到了以下错误更新,数据库-Verbose
:
I got the following error while running Update-Database -Verbose
:
使用启动项目WebApplication的。使用的NuGet项目
WebApplication的。指定-Verbose'标志来查看SQL
语句被应用到目标数据库。目标数据库是:
星冰乐(数据源:(的LocalDB)\\ V11.0,提供:
System.Data.SqlClient的,产地:配置)。无待明确
迁移。应用自动迁移:
201402032027563_AutomaticMigration。 ALTER TABLE [DBO]。[客户] ALTER
COLUMN [ID] [INT] NOT NULL System.Data.SqlClient.SqlException
(0x80131904):对象'PK_dbo.Clients'依赖于列'ID'。
对象'FK_dbo.Users_dbo.Clients_Client_ID'是依赖于柱
'ID'。 ALTER TABLE ALTER COLUMN ID失败,因为一个或多个对象
访问此列。在
System.Data.SqlClient.SqlConnection.OnError(SqlException异常,
布尔breakConnection,行动 1 wrapCloseInAction)在
1 wrapCloseInAction)在
System.Data.SqlClient.SqlInternalConnection.OnError(SQLEXCEPTION
例外,布尔breakConnection,动作
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超时,布尔asyncWrite)在
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource 1
1
完成后,字符串methodName中,布尔sendToPipe,超时的Int32,
布尔asyncWrite)在
System.Data.SqlClient.SqlCommand.ExecuteNonQuery()在
System.Data.Entity.Infrastructure.Interception.InternalDispatcher$c$c>1.Dispatch[TInterceptionContext,TResult](Func<$c$c>1
操作,TInterceptionContext interceptionContext,动作
执行,操作 1时执行)的
1
System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.NonQuery(的DbCommand
命令,DbCommandInterceptionContext interceptionContext)在
System.Data.Entity.Internal.InterceptableDbCommand.ExecuteNonQuery()结果
在System.Data.Entity.Migrations.DbMigrator.ExecuteSql(DbTransaction
交易MigrationStatement migrationStatement)在
System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ExecuteSql(DbTransaction
交易MigrationStatement migrationStatement)在
System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable的
migrationStatements,连接的DbConnection)的
System.Data.Entity.Migrations.DbMigrator&LT;> C_的 DisplayClass32.b 的_2e()
在
System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy&LT;> C_的 DisplayClass1.b 的_0()
在
System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute [TResult](Func键 1
1
操作)的
System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(动作
操作)的
System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable的
migrationStatements)在
System.Data.Entity.Migrations.Infrastructure.MigratorBase.ExecuteStatements(IEnumerable的 1
1的操作,
migrationStatements)在
System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(字符串
migrationId,的XDocument targetModel,IEnumerable的
的IEnumerable 1 systemOperations,布尔降级,布尔自动)结果
1
在System.Data.Entity.Migrations.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的
pendingMigrations,字符串targetMigrationId,字符串lastMigrationId)结果
在
System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1
pendingMigrations,字符串targetMigrationId,字符串lastMigrationId)结果
在System.Data.Entity.Migrations.DbMigrator.UpdateInternal(字符串
targetMigration)在
System.Data.Entity.Migrations.DbMigrator&LT;> C_的 DisplayClassc.b 的_B()
在
System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(动作
mustSucceedToKeepDatabase)在
System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(动作
mustSucceedToKeepDatabase)在
System.Data.Entity.Migrations.DbMigrator.Update(字符串
targetMigration)在
System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(字符串
targetMigration)在
System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run()
在System.AppDomain.DoCallBack(CrossAppDomainDelegate
callBackDelegate)在
System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)结果
在System.Data.Entity.Migrations.Design.ToolingFacade.Run(跑垒员
亚军)在
System.Data.Entity.Migrations.Design.ToolingFacade.Update(字符串
targetMigration,布尔力)在
System.Data.Entity.Migrations.UpdateDatabaseCommand&LT;> C_的 DisplayClass2&LT; .ctor>乙的_0()
在
System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(动作
命令)ClientConnectionId:9854ba62-772c-4ba6-B185-ecae993e065f的
对象PK_dbo.Clients'依赖于列'ID'。物体
FK_dbo.Users_dbo.Clients_Client_ID'依赖于列'ID'。
ALTER TABLE ALTER COLUMN ID失败,因为一个或多个对象访问
此列。
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, Action
1 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, Int32 timeout, 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()
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](Func
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(IEnumerable1 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)
1 pendingMigrations, String targetMigrationId, String lastMigrationId)
at System.Data.Entity.Migrations.DbMigrator.AutoMigrate(String migrationId, XDocument sourceModel, XDocument targetModel, Boolean downgrading) at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.AutoMigrate(String migrationId, XDocument sourceModel, XDocument targetModel, Boolean downgrading) at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable
at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, 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-第一种模式的类变量>的Int16
到的Int32
。
What I did before this is to change the ID
variables from my Code-First Model classes from Int16
to Int32
.
任何帮助吗?
推荐答案
它看起来像数据库不能修改/删除ID列,因为另一个表有一个外键引用ID列。如果删除引用,更新列,然后重新添加引用,你应该是好去...
It looks like the database can't alter/drop the ID column because another table has a foreign key referencing the ID column. If you drop the reference, update the column, and then re-add the reference, you should be good to go...
这篇关于错误在运行更新,数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!