11

I added into my model a new table:

public DbSet<ReturnedTransactions> ReturnedTransactions { get; set; }

And i want my migrations to generate that table for me, so i did:

PM> Add-migration returnedTransactions

And it generated

public partial class returnedTransactions : DbMigration
{
    public override void Up()
    {
    }

    public override void Down()
    {
    }
}

How do i force this thing to generate proper code for me?

ojek
  • 8,947
  • 19
  • 68
  • 108

5 Answers5

2

I see this happen when I do not add my DBSet Entity to my DbContext class that is associated with the Migration Configuration file.

Although, it may not be the case here as we can see that the Asker included the line:

public DbSet<ReturnedTransactions> ReturnedTransactions { get; set; }

Still, this is something one should check when they are returned an empty migration class.

Brian Merrell
  • 1,114
  • 15
  • 20
1

Clear out the _MigrationHistory table.

TLama
  • 73,451
  • 17
  • 201
  • 368
DickP
  • 21
  • 1
  • 6
    I would recommend against just randomly cleaning out `__MigrationHistory` table. That will cause Entity Framework to think that the migrations have run, and the tables have not been created. Then when Entity Framework runs the migrations, it will throw errors about the tables or columns existing. The better way is to use `Update-Database -Target:0` or similar command to remove things. – Steven V Jan 17 '14 at 14:07
0

I just had this problem and I added -Force to the Add-Migration command and it worked.

Dougmany
  • 11
  • 1
0

That may sound stupid, but do you have all needed packages installed? I have had the same problem and it turned out that a packages was missing, I think it was Microsoft.AspNetCore or Mircosoft.AspNetMVC.

maxE
  • 359
  • 1
  • 9
0

Adding to the above answer, for me I had to add Microsoft.AspNetCore.Identity.EntityFrameworkCore through NuGet in an another project, which is connected with the one containing the database context.