Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

More than one migrations configuration type was found in the assembly ''. Specify the name of the one to use. On add-migration

In Package Manager Console, I'm trying to update my database. When I enter this command :

add-migration Migration1

And I get this :

More than one migrations configuration type was found in the assembly 'MyProject.POCO'. Specify the name of the one to use.

I googled the error and I get this :

add-migration InitialBSchema -IgnoreChanges -ConfigurationTypeName
ConfigurationB -ProjectName ProjectContextIsInIfNotMainOne
-StartupProjectName NameOfMainProject  -ConnectionStringName ContextB

But I don't know how to apply this to my project. What should I write for ConfigurationTypeName? Or is there a simpler way to do this? Thanks.

like image 383
jason Avatar asked Dec 28 '16 05:12

jason


People also ask

How to enable migrations in Entity Framework Core?

Migrations are enabled by default in EF Core. They are managed by executing commands. If you have Visual Studio, you can use the Package Manager Console (PMC) to manage migrations. Alternatively, you can use a command line tool to execute Entity Framework CLI commands to create a migration.

How to remove migrations ef Core?

Delete your Migrations folder. Create a new migration and generate a SQL script for it. In your database, delete all rows from the migrations history table. Insert a single row into the migrations history, to record that the first migration has already been applied, since your tables are already there.

How to revert migration ef Core?

To revert the last applied migration you should (package manager console commands): Revert migration from database: PM> Update-Database <prior-migration-name> Remove migration file from project (or it will be reapplied again on next step) Update model snapshot: PM> Remove-Migration.

How ef migrations work?

EF Core compares the current model against a snapshot of the old model to determine the differences, and generates migration source files; the files can be tracked in your project's source control like any other source file. Once a new migration has been generated, it can be applied to a database in various ways.


1 Answers

You have multiple DbContext in your project you will need to indicate which is going to have the database update. This can be done with -ConfigurationTypeName. The ConfigurationTypeName is the name of your Configuration class in your migration folder.

Add-Migration -Name Migration1 -ConfigurationTypeName MyProject.POCO.Configuration

You can read more about it here.

like image 183
Ahmar Avatar answered Sep 20 '22 11:09

Ahmar