I am using EF code-first migrations. I added a new property to my model but it doesn't reflect as a column in the database.
Configuration.cs
public Configuration()
{
AutomaticMigrationsEnabled = true;
}
Global.asax.cs
Database.SetInitializer(new MigrateDatabaseToLatestVersion<DbContext, DbMigrationsConfiguration<DbContext>>());
using (var context = new MyDbContext())
{
context.Database.Initialize(true);
}
I have already tried the update-database
. It says no pending migrations.
EDIT:
My EF is a separate Class Library Project. There's another Class Library Project that stores all the Models. And the Main (Startup) Project is an MVC Project.
Where should I include Migrations?
Also, Add-Migrations Initial always gives me EMPTY Up() and Down() methods.
this worked for me first of all take backup of your database then delete migrations
folder in project and delete __MigrationHistory
table in database
then run this command
Enable-Migrations -EnableAutomaticMigrations -Force
then add migration
Add-Migration InitialMigration
and finally update database with
Update-Database
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With