I'm learning .net core and try to figure out the best practices for migrations. I come from Django and when when I had made a change to the database I would just do:
First:
makemigrations which is responsible for creating new migrations based on the changes you have made to your models.
Then:
migrate which is responsible for applying migrations.
Now I try to translate this to .NET Core and look at migration-commands in the Package Manager Console. I assumed that the equivalent would be to run:
First:
Add-Migration -Name <myMigration> Adds a new migration.
Then:
Update-Database -Migration <myMigration> Updates the database to a specified migration.
But then I get:
There is already an object named '<modelName>' in the database.
I'm thinking that Add-Migration didn't just add the changes to the database I've made in the Models-folder but seem to want to add everything from the Models-folder. So what am I missing here? How to I make a migration that only apply the unique changes to the database?
__EfMigrationsHistoryTable or something along the lines. This table contains an a list of entries like20170621093328_Init. It tells which migrations have been already applied2017xxxxxxxxxxx_SomeName.csfile w/o doingUpdate-Database -Migration <previous_migraton_here>, then runRemove-Migrationand then create a new migration. it's easy to mess up, especially if you can't wipe out the db and reseed it easily and don't use an version control system which allows you to roll back to a specific snapshot. Also callingUpdate-Databasewith-Migrationisn't necessary if you want to update to the most recent version. Only for rollbacks or applying not the most recent one requiredRemove-Migration -Name <migrationName>, then runDrop-Database, and goAdd-Migration -Name Initial? After that, would justAdd-Migrationwork as intended?Migrationsfolder to start from scratch. This should work as long as you never delete a migration file manually and never edit the snapshot file manually