Entity Framework Code First Migrations

Wednesday, December 19, 2018 / mcchu28


You need to use Package Management Console to run EF commands. In Visual Studio, go to Tools > NuGet Package Manager > Package Manager Console.


These are some key commands when doing EF migrations:
  • Enable-Migrations
  • Add-Migration TableAdd-YourTableName
  • update-database -script
  • Update-Database
  • Update-Database –TargetMigration: 201708161739489_TableAdd-YourTableName


update-database -script
  • generate script file that has not been applied to database yet
update-database
    • apply database migration changes to the database
    • ensure you are pointing to the right database environment in your web.config or app.config before you run this command

    For more information on Code First Migrations, visit: