Reputation: 400
I have just added 3 new classes/tables to my model with primary and foreign key constraints. When I run Add-Migration, it returns a migration with blank Up() and Down() methods.
Add-Migration 'Added Table1 Table2 Table3'
public partial class AddedTable1Table2Table3 : DbMigration
{
public override void Up()
{
}
public override void Down()
{
}
}
I have cleaned and rebuilt all necessary projects in my solution.
I have also double checked the config to ensure that the connection string is correct.
Upvotes: 0
Views: 1735
Reputation: 504
Firstly, I assume that you use Sql Server database. There is a table on the Sql Server database created by entity framework named "dbo._MigrationHistory". This table includes your migration operations along with your migration classes.
When you create and execute a migration on Package Manager Console, Visual Studio not only checks your model changes but also check this file on your database. It is possible that some sync issues between your model and dbo._MigrationHistory file. In such a case, entity framework does not create correct migration file like you mentioned above. You can try to delete last record from dbo._MigrationFile to solve the issue. Good luck
Upvotes: 1
Reputation: 400
It turned out that I was missing a reference to the new tables in my DataContext. The solution was to add the three new tables to the DataContext. The migrations worked as expected.
public DbSet<Table1> Table1Collection { get; set; }
public DbSet<Table2> Table2Collection { get; set; }
public DbSet<Table3> Table3Collection { get; set; }
Upvotes: 1