smartstore / SmartStoreNET

Open Source ASP.NET MVC Enterprise eCommerce Shopping Cart Solution
http://www.smartstore.com/en/net
GNU General Public License v3.0
2.64k stars 1.46k forks source link

Unable to Apply Migrations #2163

Closed PixelDevelopers closed 4 years ago

PixelDevelopers commented 4 years ago

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 have downloaded the source code for V4.1.0 have installed my store - I have been using the past couple of days and building my theme. The solution runs and is installed properly. The settings.txt file exists etc.

However, I require to add a new column onto the Product Table. I have updated the domain class in .core and attempted to add-migration but receive the above error. Changing the AutomaticMigrationsEnabled to true also doesnot help. So I am stuck, any help would be appreciated.

muratcakir commented 4 years ago

You have to switch Build configuration in Visual Studio to EFMigrations, then rebuild SmartStore.Data project. Switch back to Debug and try again.

Most likely the EF designer tools can't find dependant assemblies.

PixelDevelopers commented 4 years ago

I'm afraid that doesn't work. I get the same error.

mgesing commented 4 years ago

Here are some related forum links that might help: http://community.smartstore.com/index.php?/topic/47346-migration-error-when-trying-to-upgrade-to-v222/ http://community.smartstore.com/index.php?/topic/49101-connection-string-problems/ http://community.smartstore.com/index.php?/topic/49176-smartstore-error/page-3

PixelDevelopers commented 4 years ago

Hi mgesing,

Thanks for sharing those forum links, I have gone through so many without getting this working. But one you shared did help! I'm going to paste an extract from it in case anyone else experiences the same issue and comes across my post.

_"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("~/AppData/", 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."

Note: Build Configuration still should be EFMigrations

Thanks again!!