I had MVC4 project with Identity 2.0 that was not created automatically by using MVC template. Nothing was changed there. Then I decided to migrate to the project to the MVC6 + EF7. I've created the 1 more project in the same solution and moved all the objects there. When I am trying to run the application EF tries to create the objects that already exists so the application fails with following message:
SqlException: There is already an object named 'AspNetRoles' in the database.
I've tried to google it and found the proposal to run:
Add-Migration Initial -IgnoreChanges
Then I am getting following error message:
Exception calling "SetData" with "2" argument(s): "Type 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProject' in
assembly 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not
marked as serializable."
At C:\Users\user\Source\Repos\Proj.Accounting\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:720 char:5
+ $domain.SetData('startUpProject', $startUpProject)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SerializationException
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Data.Entity.Migrations.Extensions.ProjectExtensions.GetProjectTypes(Project project, Int32 shellVersion)
at System.Data.Entity.Migrations.Extensions.ProjectExtensions.IsWebProject(Project project)
at System.Data.Entity.Migrations.MigrationsDomainCommand.GetFacade(String configurationTypeName, Boolean useContextWorkingDirectory)
at System.Data.Entity.Migrations.AddMigrationCommand.Execute(String name, Boolean force, Boolean ignoreChanges)
at System.Data.Entity.Migrations.AddMigrationCommand.<>c__DisplayClass2.<.ctor>b__0()
at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
Object reference not set to an instance of an object.
So my question is: how to disable EF migrations? I am using OLEDB to access database and EF is used only for the Identity.
UPDATE: by suggested answer below I've tried to add following line
Database.SetInitializer<ApplicationDbContext>(null);
to the Startup class constructor
Severity Code Description Project File Line Error CS0311 The type 'Proj.Accounting.Web.Angular.Models.ApplicationDbContext' cannot be used as type parameter 'TContext' in the generic type or method 'Database.SetInitializer(IDatabaseInitializer)'. There is no implicit reference conversion from 'Proj.Accounting.Web.Angular.Models.ApplicationDbContext' to 'System.Data.Entity.DbContext'. Proj.Accounting.Web.Angular.DNX 4.5.1 C:\Users\User\Source\Repos\Proj.Accounting\Proj.Accounting.Web.Angular\Startup.cs 50