Inhalte aufrufen

Profilbild

Migration error when trying to upgrade to v2.2.2


  • Bitte melden Sie sich an, um eine Antwort zu verfassen.
11 Antworten zu diesem Thema

#1 nickh

nickh

    Erfahrener Benutzer

  • Members
  • 129 Beiträge

Geschrieben: 25 October 2015 - 17:47

Hi guys,

 

I've been using v2.1 for a while and decided to try to upgrade to v2.2.2 today, but I have run into entity framework migration issues because I had made other database changes (using EF migrations) before applying v2.2.2 changes.

 

This is the error that I see when the I target the 2.2.2 installation at my modified v2.1 database:

 

  • Setup failed: Unable to update database to match the current model because there are pending changes and automatic migration is disabled. Either write the pending model changes to a code-based migration or enable automatic migration. Set DbMigrationsConfiguration.AutomaticMigrationsEnabled to true to enable automatic migration.

 

The problem is that I can't run either update-database or add-migration commands, because the NuGet console gives me the following error when I try (with the Default Project drop down set to SmartStore.Data, and even using the EFMigration Build Configuration):

 

A connection string could not be resolved for the parameterless constructor of the derived DbContext. Either the database is not installed, or the file 'Settings.txt' does not exist or contains invalid content.

 

My Settings.txt file exists in App_Data (and the connection string is perfect).

 

This sounds very similar to this reported bug: https://github.com/s...eNET/issues/617, but none of the suggestions work.

 

What is causing this problem?


  • kdenisinfo gefällt das

#2 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3799 Beiträge

Geschrieben: 26 October 2015 - 12:10

Select Debug or Release Build Configuration if you want to add a migration to SmartStore.Data.
 
Add an ignoring changes migration to solve migration conflicts ("Unable to update database to match the current model because there are pending changes and automatic migration is disabled"):
add-migration nickh -IgnoreChanges

Marcus Gesing

Smartstore AG


#3 nickh

nickh

    Erfahrener Benutzer

  • Members
  • 129 Beiträge

Geschrieben: 26 October 2015 - 12:26

Hi Marcus,

 

Thanks, but I have already tried to add a migration using both the Debug and Release build configuration, and both still give the same error:

 

A connection string could not be resolved for the parameterless constructor of the derived DbContext. Either the database is not installed, or the file 'Settings.txt' does not exist or contains invalid content.

 

I'm unable to run the 'add-migration' command that you've suggested because of the above error!


  • kdenisinfo gefällt das

#4 Murat Cakir

Murat Cakir

    SmartStore AG

  • Administrators
  • 1118 Beiträge

Geschrieben: 26 October 2015 - 19:00

Did you also select SmartStore.Data as starting project in the package manager console? This is often forgotten.


  • kdenisinfo gefällt das

Murat Cakir
SmartStore AG


#5 nickh

nickh

    Erfahrener Benutzer

  • Members
  • 129 Beiträge

Geschrieben: 26 October 2015 - 19:40

Yes - same problem.



#6 Murat Cakir

Murat Cakir

    SmartStore AG

  • Administrators
  • 1118 Beiträge

Geschrieben: 26 October 2015 - 20:54

Well, that's strange. Does the file App_Data/Settings.txt exist in your local (dev) installation and does its content point to the correct database? 


Murat Cakir
SmartStore AG


#7 nickh

nickh

    Erfahrener Benutzer

  • Members
  • 129 Beiträge

Geschrieben: 26 October 2015 - 22:39

Yes, and yes. Could it be because of the existing data in the _migrationHistory table?

#8 Murat Cakir

Murat Cakir

    SmartStore AG

  • Administrators
  • 1118 Beiträge

Geschrieben: 27 October 2015 - 17:41

Yes, and yes. Could it be because of the existing data in the _migrationHistory table?

 

I doubt it, because you're not even able to successfully connect to the database.

 

When you executed add-migration from the command line, was EFMigration your active build configuration? It should be.


Murat Cakir
SmartStore AG


#9 nickh

nickh

    Erfahrener Benutzer

  • Members
  • 129 Beiträge

Geschrieben: 27 October 2015 - 20:26

When you executed add-migration from the command line, was EFMigration your active build configuration? It should be.

 

Yes it was (although I've also tried it with Debug and Release build configurations too).



#10 nickh

nickh

    Erfahrener Benutzer

  • Members
  • 129 Beiträge

Geschrieben: 27 October 2015 - 23:22

I've just spent the last 4 hours trying to resolve this and I'm now completely frustrated.  The Settings file is perfect, but the migrations just will not run.  All signs point to an error during instantiation (perhaps with dependency injection?).  It's EXACTLY the same problem as mentioned here, but none of the suggested solutions seem to work.

 

Surely this has been tested on an existing DB before...?



#11 Murat Cakir

Murat Cakir

    SmartStore AG

  • Administrators
  • 1118 Beiträge

Geschrieben: 28 October 2015 - 01:04

I can totally understand your frustration. Sometimes EF migrations can drive you mad. But let's try the following:

  • Manually create the folder App_Data in [ProjectFolder]\src\Libraries\SmartStore.Data\bin\EFMigrations
  • Copy your Settings.txt over to the new folder
  • In VS: change line 172 in SmartStore.Core/Data/DataSettings.cs

From:

string filePath = Path.Combine(CommonHelper.MapPath("~/App_Data/"), FILENAME);

To:

string filePath = Path.Combine(CommonHelper.MapPath("~/App_Data/", false), FILENAME);

The false parameter instructs the PathMapper not to fallback to the solution's root folder, but instead work in src\Libraries\SmartStore.Data\bin\EFMigrations, which is actually the base directory during EF migration console operations. With this workaround EF Tooling should be able to successfully resolve your settings file. At least now you should be able to execute commands.


Murat Cakir
SmartStore AG


#12 nickh

nickh

    Erfahrener Benutzer

  • Members
  • 129 Beiträge

Geschrieben: 28 October 2015 - 08:25

Hi Murat,

 

Thanks - that worked!