1

Is there any possible way to create migration on runtime in efcore.

context.Database.Migrate(); 

Before this code, I need a code that, when I started my app, should create a migration about diff between postgresql database tables and ef models.

Is there any way to do this?

PM> enable-migrations PM> add-migration initial PM> update-database 

I dont want to use these ones. I want to make these code's jobs on runtime. I hope I could explain myself clearly.

1
  • I haven't done it myself, but it seems it's possible through the EF Core APIs. For example this IMigrationsModelDiffer interface lets you compare two models and generate an migration if they differ, Commented Apr 19, 2020 at 12:34

1 Answer 1

2

Note, you need to re-compile the app after calling Add-Migration. It's very difficult to do this while the app is running.

Have a read through the closed Automatic Migrations issue for some alternative solutions.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.