When I try to create a new migration using EF Code-First the package manager console gives me an error saying: 'No migrations configuration type was found in the assembly 'Project.DataAccess'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration).'
I've previously used this method on THIS project successfully and the project do have a Configuration file with all the correct inheritance.
I also tried specifying all the parameters -Name, -StartupProjectName etc. but no change. When trying to re-enable migrations VS is not successful creating the Configuration with inheritance from my context-class.
Any suggestion on this issues? Using EF 4.3.1 and Code-First
This problem was resolved by installing EF 4.3.1 using the Package Manager Console. I had done a manual upgrade and for some reason that didn't do the trick.
Related
I have .net Core 3.1 solution with WebApi and Persistance projects. WebApi is the solution's startup project, Persistance is where DbContext is defined. After a lot of reading and trying stuff, I still cannot achieve the following:
WebApi stays as the solution's startup project.
Migrations folder with all the migrations classes is in the Persistance project.
Migrations can be generated from VS Package Manager Console by typing Add-Migration <migration_name> without any additional parameters like -Project or -StartupProject.
No need to change selection in the Package Manager Console Default project dropdown.
I wanted to achieve the same result but on MAC OS. Because Visual Studio on Mac is not like Window's, We use CLI commands. In my case I had Migration Classes in another project and startup was Api project just like you so i added this to my terminal :
alias migrationfortest='dotnet ef migrations add $1 --project /Users/user/Projects/test-web/Test.Infrastructure'
and you can call this simply by typing migrationfortest "YOURMIGRATIONNAME"
NOTE : For CLI command tools you should add This
I am working on an ASP.NET Core MVC app. I deleted the Migrations file and folder. I try again using .NET EF Core migration and adding initial, but I see the build failed. How can I do this?
Your question does not explain many things like did you created any other class or namespace in migrations folder and accidentally deleted it as well.
Build failed error is caused by some missing file, reference or some syntax error.
Check you Error List tab in visual studio.
I use to write my command ">dotnet ef migrations add initial" in CLI and I could see only "Build Failed" . Then I used Package Maneger Console "PM> add-migration initial" and take more description. when I fixed errors I am succed successful
[Link]https://www.entityframeworktutorial.net/efcore/entity-framework-core-console-application.aspx
after I execute the add-migration in the PMC the migration class is created with all the correct changes need in the Up method.
When I run the update-database command in the PMC I get the error
System.InvalidOperationException: The migration '***MigrationName***' was not found.
I have never seen this before and the file it says is not there clearly exist.
If I execute the remove-migrations command the newly created migration class is not removed, I get an error stating that the previous migration has already been applied.
It appears that all new migrations created with add-migrations are not recognized via the update-database or remove-migration commands
One of the reasons for this is that dbcontext is not in startup project and it is inside another project. In this case PM may not be able to find routes to complete migrations. We can use dotnet with explicit dbcontext and proj name where dbcontext is:
dotnet ef database update --context YourAppContext --project YourProj
We just had the same issue. The problem was that, we excluded the Migrations folder from the solution in Visual Studio.
Project ⇒ Show all files
Right Click on "Migrations"
» Include in project
The above steps resolved it for us.
I am trying to use EF7 with the old project type (csproj)
If I run Add-Migration in package manager, it complains that it cannot find package EntityFramework. I guess it is looking for the EF6 EntityFramework project, since such a project does not exist anymore? How can I force it to use EF7 Add-Migration cmdlet?
I have tried running ef commands with dnx in the "wrap" folder, but that seems needlessly complicated and it doesn't work (it cannot find any framework dependencies at all)
Any ideas?
Have you installed EntityFramework.Commands? https://www.nuget.org/packages/entityframework.commands
Also, using EF6 and EF7 in the same solution is going to cause some problems. It's probable that Add-Migration failed because you are actually running the EF6 command. Check if the command Use-DbContext exists, which is new to EF7.
I have looked around stackoverflow and search the internet but did not find a answer.
If i try to Enable-Migrations for my project i get the Exception
Error while searching for context type (specify -Verbose to see exception details).
Edit the generated Configuration class to specify the context to enable migrations for.
So my question is:
What are the requirements for my project / DbContext in order to let the Entity Framework Migrations find my DbContext WITHOUT specifying it manually ?
Thanks in advance!
You project will need a database class which derive from DbContext, and in your web.config/app.config, you will need a connection string which points to the right database which is used by your database class.
The project you run the command on will need a configuration file to have the right connection string. Even it's class library, you still need this configuration.
I have had a similar issue which was related to the wrong version of Entity Framework being referenced.
You can try executing Update-Package EntityFramework from the Package Manager Console in Visual Studio.
If that does not help then just manually reference the EF 4.3 library from your project and then re-run the Enable-Migrations -force for your project(s).
Cheers.