How to apply same name to different migrations?

asp.net-core-mvc ef-migrations entity-framework-core

Question

Entity Framework Core doesn't allow me to name different migrations with same name. Although the names will still be different, because the timestamp is always different. The error is:

The name '_' is used by an existing migration.

Previous version of EF (.NET Framework) allowed to do this.

1
1
2/11/2019 10:30:45 AM

Accepted Answer

Although the names will still be different, because the timestamp is always different

This is not entirely correct. Although the name of the migration uses a timestamp in it, the name of the generated migration class itself would be the name without any timestamp.

This name is generated inside the CSharpMigrationsGenerator class using ICSharpHelper.Identifier. An instance implementing this interface is injected using dependency injection which does sound to possess ability of overriding implementation with your own code, however I do not see this happening using the out of the box command line tools, you might need to re-invent your own migrations tool or do that from your application code.

And even if you do manage to overcome this part, there are other internal stuff you would need to handle. For instance, IMigrationsAssembly.Migrations also holds the names of the migrations without the timestamp part, therefore you would still need to adjust the names so that they are unique, because the dictionary simply does not allow duplicate keys.

Summa summarum, it might be possible, but doesn't sound to be worth the effort with the current version of EF Core.

1
2/11/2019 10:57:07 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow