ojek
ojek

Reputation: 10068

EF add-migration generates empty migration

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?

Upvotes: 11

Views: 9904

Answers (6)

Alloylo
Alloylo

Reputation: 301

Check the created table in the "ApplicationDbContextModelSnapshot" class, This class is added to the Migrations folder when the first migration is made and updated with each subsequent migration. Try to clear the new table if it's there or deletes this class. It worked for me.

Upvotes: 1

Kristiyan Ivanov
Kristiyan Ivanov

Reputation: 53

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.

Upvotes: 0

maxE
maxE

Reputation: 361

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.

Upvotes: 0

Dougmany
Dougmany

Reputation: 11

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

Upvotes: 0

Brian Merrell
Brian Merrell

Reputation: 1174

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.

Upvotes: 3

DickP
DickP

Reputation: 21

Clear out the _MigrationHistory table.

Upvotes: 1

Related Questions