简体   繁体   English

无法在Azure SQL数据库上创建新的EF迁移

[英]Unable to create a new EF migration on Azure SQL Database

I have an Azure SQL Database (V12) which I am using with EF6 and db migrations. 我有一个正在与EF6和数据库迁移一起使用的Azure SQL数据库(V12)。 In the past, I have successfully performed database changes with migrations (with Add-Migration and Update-Database ). 过去,我已经成功地通过迁移(使用Add-MigrationUpdate-Database )执行了数据库更改。 Recently I attempted another change, and have been met with a null ref exception when performing the Add-Migration command. 最近,我尝试了另一项更改,并且在执行Add-Migration命令时遇到了null ref异常。

I've tried all sorts of workarounds, but I seem to get this error regardless. 我已经尝试了各种解决方法,但是无论如何我似乎都收到此错误。 Even when I try to generate an empty migration (with no changes), I still get this error. 即使我尝试生成一个空的迁移(没有任何更改),我仍然会收到此错误。 Is there any way to debug this issue, or does anyone have any insight into what this means? 有什么方法可以调试此问题,或者没有人对这意味着什么有任何见识? Thanks! 谢谢!

EDIT: I used the sql migration tool to copy the database over to an SQL Server 2014 VM, and the migration went fine - is it possible that this is an SQL Azure V12 problem? 编辑:我使用sql迁移工具将数据库复制到SQL Server 2014 VM中,并且迁移顺利-是否可能是SQL Azure V12问题?

Here is the stack trace: 这是堆栈跟踪:

    System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Data.SqlClient.TdsParser.TrySkipRow(_SqlMetaDataSet columns, Int32 startCol, TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.TrySkipRow(_SqlMetaDataSet columns, TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at System.Data.SqlClient.SqlDataReader.TryCloseInternal(Boolean closeReader)
   at System.Data.SqlClient.SqlDataReader.Close()
   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<Reader>b__c(DbCommand t, DbCommandInterceptionContext`1 c)
   at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
   at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)
   at System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
   at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__6()
   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__5()
   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
   at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
   at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__3[TResult](IEnumerable`1 sequence)
   at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot)
   at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[TResult](Expression expression)
   at System.Data.Entity.Internal.Linq.DbQueryProvider.Execute[TResult](Expression expression)
   at System.Linq.Queryable.Count[TSource](IQueryable`1 source, Expression`1 predicate)
   at System.Data.Entity.Migrations.History.HistoryRepository.QueryExists(String contextKey)
   at System.Data.Entity.Migrations.History.HistoryRepository.Exists(String contextKey)
   at System.Data.Entity.Migrations.History.HistoryRepository.GetPendingMigrations(IEnumerable`1 localMigrations)
   at System.Data.Entity.Migrations.DbMigrator.GetPendingMigrations()
   at System.Data.Entity.Migrations.DbMigrator.Scaffold(String migrationName, String namespace, Boolean ignoreChanges)
   at System.Data.Entity.Migrations.Design.MigrationScaffolder.Scaffold(String migrationName, Boolean ignoreChanges)
   at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.Scaffold(MigrationScaffolder scaffolder)
   at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.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.Scaffold(String migrationName, String language, String rootNamespace, Boolean ignoreChanges)
   at System.Data.Entity.Migrations.AddMigrationCommand.Execute(String name, Boolean force, Boolean ignoreChanges)
   at System.Data.Entity.Migrations.AddMigrationCommand.<>c__DisplayClass2.<.ctor>b__0()
   at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)

I'm still hoping someone will be able to post a proper solution - in the meantime if anyone else has this issue, here's how I am able to temporarily solve it. 我仍然希望有人能够发布适当的解决方案-同时,如果其他人遇到此问题,这就是我能够临时解决的方法。

The main issue appears to be that EF cannot generate a migration for a SQL Azure V12 database, where a previous migration has been done. 主要问题似乎是EF无法为已完成先前迁移的SQL Azure V12数据库生成迁移。 When performing the Add-Migration command, a NRE occurs (without much helpful info). 当执行Add-Migration命令时,会发生NRE(没有太多有用的信息)。

After some experimenting, I've found that I can copy over the schema of my db and the data from the _MigrationHistory tables to a SQL Server 2014 instance, and perform the Add-Migration targetting that shell db, in order to generate the migration classes. 经过一些试验,我发现我可以将数据库的架构和_MigrationHistory表中的数据_MigrationHistory到SQL Server 2014实例,并以该Shell db为目标执行Add-Migration ,以生成迁移类。 。 After that, I re-target my Azure SQL database, and run Update-Database to perform the migration. 之后,我重新定位Azure SQL数据库,并运行Update-Database来执行迁移。 This is definitely NOT ideal, but will work as a stop gap until I can hopefully find a real fix. 这绝对不是理想的,但是会起到一定的作用,直到我希望找到真正的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM