Entity Framework Code-First: Generate SQL script with 'Update-Database' produces XML error while parsing

c# ef-code-first ef-migrations entity-framework

Question

Entity Framework 6.0,.NET 4.5, FAT-Client, and the Code-First methodology are all used in our project.

The cmdlet has created roughly 20 migration-files (C# partial classes) automatically.Add-Migration deployed successfully using the Visual Studio Package Manager ConsoleUpdate-Database .

Currently, we need to deploy the last 10 migrations to our client's integration database, which has previously had around 10 migrations applied. By usingUpdate-Database -Script -SourceMigration:<migration10> creating a SQL script for the remaining migrations requires this. In this instance, as well as when usingSourceMigration:$InitialDatabase The following error message appears:

[...]
Applying explicit migration: 201609141617112_HostAufbauIdentifier.
Applying explicit migration: 201609141622583_RemPerStaWe.
System.Xml.XmlException: 'SoftwareAuftrag_Auftrag' is an unexpected token. Expecting white space. Line 1943, position 92.
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
   at System.Xml.XmlTextReaderImpl.ThrowExpectingWhitespace(Int32 pos)
   at System.Xml.XmlTextReaderImpl.ParseAttributes()
   at System.Xml.XmlTextReaderImpl.ParseElement()
   at System.Xml.XmlTextReaderImpl.ParseElementContent()
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r)
   at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o)
   at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
   at System.Xml.Linq.XDocument.Load(Stream stream, LoadOptions options)
   at System.Data.Entity.Migrations.Edm.ModelCompressor.Decompress(Byte[] bytes)
   at System.Data.Entity.Migrations.DbMigration.GetModel(Func`2 modelAccessor)
   at System.Data.Entity.Migrations.DbMigration.GetTargetModel()
   at System.Data.Entity.Migrations.DbMigrator.ApplyMigration(DbMigration migration, DbMigration lastMigration)
   at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ApplyMigration(DbMigration migration, DbMigration lastMigration)
   at System.Data.Entity.Migrations.Infrastructure.MigratorBase.ApplyMigration(DbMigration migration, DbMigration lastMigration)
   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 targetMigrationId, String lastMigrationId)
   at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
   at System.Data.Entity.Migrations.Infrastructure.MigratorScriptingDecorator.ScriptUpdate(String sourceMigration, String targetMigration)
   at System.Data.Entity.Migrations.Design.ToolingFacade.ScriptUpdateRunner.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.ScriptUpdate(String sourceMigration, String targetMigration, Boolean force)
   at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0()
   at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)

Here's where to find the problematic file:201609141622583_RemPerStaWe absolutely nothing that bears the label of is done.SoftwareAuftrag or similar. Prior migrations carried out this work, and I don't observe any issues there either.

I attempted to connect the debugger using code, but I have no idea where to place the breakpoint. Breaks don't seem to be triggered in this situation by the option to "break when an exception occurs." The package manager may have begun another sub-process.

We waste a lot of time on this since I have no idea how to break down the issue. I'm hoping someone has a tip on this.

UPDATE

Up until I discovered precisely 3 migration files that when combined create the problem, I removed each one one at a time. However, if I remove all of the comments,up and down The problem continues. When deleting the whole 3 migration files, the error is gone. Which part of it makes sense? Resource files have issues? I'm not sure...

1
3
9/28/2016 11:42:37 AM

Popular Answer

I often issue commands like:

Update-Database -Script 
       -SourceMigration:"201502201618119_Migrations17"   
       -TargetMigration:"201503031134340_Migrations18"

then have the server execute the resulting script.SourceMigration is the last entry in the__MigrationHistory on the server's table.

The second "technique" I use when dealing with migration issues is to remove migration scripts from the server that have not yet been deployed.Add-migration again. It's possible that this is being caused by a disagreement between two migrations. Do this instead of modifying each script separately.

UPDATE: The above timestamp is not necessary. For instance:SourceMigration:"Migrations17" is all that's necessary.

12
12/3/2017 10:37:13 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow