Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to control which order the EF Core run custom migrations?

I am running an application that uses custom migrations (the auto generated ones don't fit my requirements). I am trying to understand how to control in which order the Entity Framework will run those migrations. I read on some places that using timestamp on the file names will do it, but that does not work. (it runs 20190131153312_bla before 20190131153208_bla2, for example)

No matter where I look I can't seem to find information on this subject... can anyone help?

like image 606
Shany Samuel Benedict Topper I Avatar asked Feb 03 '19 08:02

Shany Samuel Benedict Topper I


People also ask

How do I run down ef core migration?

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 do I change migrations in assembly?

By default, the migrations assembly is the assembly containing the DbContext. Change your target project to the migrations project by using the Package Manager Console's Default project drop-down list, or by executing "dotnet ef" from the directory containing the migrations project."

How do I add a migration to multiple DbContext?

One way to create multiple migration sets is to use one DbContext type per provider. Specify the context type when adding new migrations. You don't need to specify the output directory for subsequent migrations since they are created as siblings to the last one.


1 Answers

Migration file and class names doesn't matter.

The order of migrations is determined by the migration identifier (string), which is provided by the Id property of the MigrationAttribute associated with the Migration derived classes.

EF Core tools prepend timestamp to the user supplied migration names in order to ensure proper string ordering.

like image 199
Ivan Stoev Avatar answered Oct 11 '22 05:10

Ivan Stoev