What is the difference between Automatic Migration vs Code-base Migration?

Technology CommunityCategory: Entity FrameworkWhat is the difference between Automatic Migration vs Code-base Migration?
VietMX Staff asked 3 years ago

Automatic migration is just a magic tool. You run your application and you will always get your database in the latest version because EF will do implicit migration every time it is needed – in the purest version you never need to do anything more than enabling automatic migrations.

Automatic migrations are sometimes not enough. You need to add some customization to migration code or run some additional SQL commands for example to transform data. In such case you add explicit code based migration by calling Add-Migration command. Explicit migration shows all migration code which will be executed during migration (there is no additional magic).

If you turn off automatic migrations you must always define explicit migration to define database upgrading process in well defined explicit steps. This is especially useful for scenarios where you need to use both upgrading and downgrading to specific version.