Entity Framework 4.3 migrations error

29,287

Solution 1

Solution found. It turns out, that you need to enable migrations for your project. You can do this by running Enable-Migrations in the NuGet console (make sure you have the right project selected - for me this was the project.domain project).

This walkthrough provides more information

Solution 2

Sometimes, even if you have enabled migration, this problem can occur. It means that configuration file has been deleted. In this case, you can run

Enable-Migrations -Force 

in the Package Manager Console. -Force parameter is to override migration configuration file.

Solution 3

If you had already enabled migrations and just started seeing this error after some windows updates, ensure you are using the same version of Entity Framework across all projects using the NuGet Package Manager.

Recent windows updates may have installed a newer version of Entity Framework into your active project.

Background: Around 16 Mar 2016, I started getting the "no migrations configuration type" error when trying to add migrations to a project where I had already enabled migrations and had successfully done migrations before.

I noticed that around March 10, a new stable version of Entity Framework 6 had been released.

If I specified the -ContextTypeName parameter in the enable-migrations command, I got an error indicating the migrations were already enabled.

Another error I got as I was troubleshooting indicated that the Configuration type was not inheriting from the System.Data.Entity.ModelConfiguration.EntityTypeConfiguration, even though it was.

That led me to believe different versions of the Entity Framework were conflicting.

Resolution:

1) Tools -> Nuget Package Manager -> Manage Nuget Packages for Solution

2) (Not sure if this step is necessary, but..) I updated my version of the Nuget Package Manager to the latest version. Also, after updating my version of Nuget Package Manager, I had to restart Visual Studio twice before the NuGet Command line would work properly.

3) Tools -> Nuget package Manager -> Manage Nuget Packages for Solution -> Search Installed packages -> Type Entity Framework

a. You may see more than one version of Entity Framework there.

b. Click Manage on each version of Entity Framework and ensure that your projects are using the SAME version of Entity Framework. •Uncheck the version of Entity Framework that you are not using and for the version of Entity Framework you ARE using make sure it is checked across your projects that need it.

Again, as noted in step 2, I had to restart visual studio twice to get the NuGet Package Manager Console to work properly after updating my version of the NuGet Package Manager. I got an error starting the console the first time, and "exception calling createinstancefrom with 8 arguments could not load file or assembly EntityFramework" when running the enable-migrations command the second time.

Restarting visual studio seemed to resolve those issues, however.

Share:
29,287
Matt Roberts
Author by

Matt Roberts

Updated on October 09, 2020

Comments

  • Matt Roberts
    Matt Roberts over 3 years

    I've just installed EF 4.3-beta1 for the migrations goodness, and I can't get it working. The error I get:

    PM> Update-Database -Verbose
    Using NuGet project 'Project.Domain'.
    Using StartUp project 'ProjectWebSite'.
    System.InvalidOperationException: No migrations configuration type was found in the assembly 'Project.Domain'.
       at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.FindConfiguration()
       at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.GetMigrator()
       at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.RunCore()
       at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
    No migrations configuration type was found in the assembly 'Project.Domain'.
    

    I've added a new column to 2 EF classes:

    public class MasterInstance
    {
        public int MasterInstanceId { get; set; }
        [Required] public string HostName { get; set; }
        [Required] public string Name { get; set; } /* <-- THIS IS NEW */
        [Required] public string ConnectionString { get; set; }
        public virtual ICollection<MasterInstanceLocation> MasterInstanceLocations { get; set; }
    }
    

    And my DbContext looks like this:

    public class ProjectDontext: DbContext, IProjectContext
    {
        public IDbSet<Installer> Installers { get; set; }
        public IDbSet<MasterInstance> MasterInstances { get; set; }
        public IDbSet<MasterInstanceLocation> MasterInstanceLocations { get; set; }
    }
    

    Any ideas? My EF classes & context live in a separate assembly (Project.Domain). I've tried running the update-database in the context of both the main website and the domain project, and I get the same error either way.

    -- EDIT --

    Solution found. It turns out, that you need to enable migrations for your project. You can do this by running Enable-Migrations in the NuGet console (make sure you have the right project selected - for me this was the project.domain project).

    This walkthrough provides more information

  • R. Salisbury
    R. Salisbury over 8 years
    >make sure you have the right project selected This was my problem. Make sure the right project is selected.
  • Pati K
    Pati K almost 5 years
    I would add to NOT use add-migration. Just enable them and run project.