I am a beginner in ASP.NET MVC 5 and I was building a small application. While I was adding a controller a message popped up saying: \"There was an error running the selected co
Make sure you set throwIfV1Schema
to false
in the constructor of your DbContext, e.g.
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext() : base("DefaultConnection", throwIfV1Schema: false) { }
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
There could be a discrepancy between your model and connection string. Have you created a model? If so, then your DbContext class name must match the one specified in your connection string. It's also case sensitive. See the example below.
---Model class---
Public Class Model
Public Property ...
End Class
Public Class ModelDbContext
Inherits DbContext
Public Property Models As DbSet(Of Model)
End Class
Make sure to import Imports System.Data.Entity
Your connection string should be something like this:
<add name="ModelDbContext"
connectionString="Data Source=LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\Models.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />