YuriyP
YuriyP

Reputation: 4478

EF 7 Migrations. Web project, DBContext and Migrations in different assemblies

I have three projects in my solution.

BaseApp.Data - which holds my DBContext.

BaseApp.Data.ProjectMigration - which holds all migration files (depends on BaseApp.Data)

BaseApp.Web - web application with Startup class.

I added my first migration like this:

dnx ef migrations add Initial -p BaseApp.Data.ProjectMigration

After this command the Migrations folder appears with all corresponding files in BaseApp.Data.ProjectMigration. So everything is ok so far.

Than I try to apply migrations:

dnx ef database update

After this command the database is created, but no migrations applied. I also tried

dnx ef database update -p BaseApp.Data.ProjectMigration

with same result. Also next command returns "No migrations were found".

dnx ef migrations list -p BaseApp.Data.ProjectMigration

Also if I add migrations to BaseApp.Data then everything works fine. The next commands work as expected:

dnx ef migrations add Initial -p BaseApp.Data

dnx ef database update

So is it possible to hold migration files not in DBContext project?

Upvotes: 2

Views: 1237

Answers (1)

bricelam
bricelam

Reputation: 30375

You'll also need to set your migrations assembly.

options.UseSqlServer(connectionString)
    .MigrationsAssembly("BaseApp.Data.ProjectMigration");

Upvotes: 3

Related Questions