You might get this error while doing update-database -verbose via Package Manager Console:
No pending code-based migrations.
Applying automatic migration: 201310081433521_AutomaticMigration.
Automatic migration was not applied because it would result in data loss.
This error happens when your data model is not in synch with your database. There are two ways to fix this:
The first approach is by adding/deleting the columns that you added/dropped manually to your table and then re-running update-database again. The second approach is to force the update by issuing:
update-database -verbose -force
Doing so will force the update and recreate your columns and tables.
I was working on a sample project today when I encountered this error after adding a new Console Application project to my Visual Studio solution that references other Class Library projects contained in the solution:
The referenced assembly “C:devcenterdotnetpersonalKeithRull.BibliaKeithRull.Biblia.Service.RepositorybinDebugKeithRull.Biblia.Service.Repository.dll” could not be resolved because it has a dependency on “System.Web, Version=22.214.171.124, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” which is not in the currently targeted framework “.NETFramework,Version=v4.0,Profile=Client”. Please remove references to assemblies not in the targeted framework or consider retargeting your project. KeithRull.Biblia.ConsoleApp.
There are two possible cause of this error. The first possible reason is when you have an assembly that is referencing System.Web and you try to add that assembly to project that does not have any reference to System.Web (if necessary which most of the time is not). The second possible reason is that your project is using the .NET 4.0 Client Profile which is just a subset of the .NET Framework. Below are the steps that illustrate how to fix this issue.
1. Select your project, right-click and then select “Properties”.
2. The properties tab, change the value for “Target Framework” and then set it’s value to “.NET Framework 4”
Compile your application and that should fix the problem.
Interested in learning more? Below are some useful links if you want to read more about this issue and the .NET 4 Client Profile.