EF migration shows empty Up() Down() methods

I have a local database that is currently in it's second version and should now go to it's third version.

The code for the previous migrations was generated by another programmer so I am assuming I am doing something wrong here.

In my model there are around 30 classes, and inside the model folder there is a mapping folder and it contains the mappings for those 30 classes.

So now I added 1 new class in the same manner as those previous classes and then run the add-migration command in the Package Manager Console.

Infortunately I get an empty migration Up() and Down() method.

When I look in the database there is a __migrationHistory available with the previous 2 migrations. If I run my application now, the third migration is also added but obviously the new table is not being created because it's not in the Up() method.

What could I be doing wrong?

I think something is going wrong when scaffolding the previous migrations... It's like it can't find the new Code-First classes I have added.

This is my command:

add-migration "1.2" -verbose -ProjectName "MyEFproject"

I am assuming that the scaffolding doesn't know where to look for the new class... or is this by convention that all model classes are just expected to be in the project?

Result of add-migration:

namespace MyProject.Migrations
{
using System;
using System.Data.Entity.Migrations;

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

    public override void Down()
    {
    }
}
}

Sample of new Model Class:

using System;
using System.Collections.Generic;

namespace MyProject.Models
{
public partial class MyTable
{

    public string SomeId { get; set; }
    public string SomeText { get; set; }


}
}

Sample of new Mapping class

using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace MyProject.Models.Mapping
{
 public class MyTableMap : EntityTypeConfiguration<MyTable>
{

    public MyTableMap()
    {
        // Primary Key
        this.HasKey(t => t.SomeId);

        // Properties
        this.Property(t => t.SomeText)
            .IsRequired()
            .HasMaxLength(30);



        // Table & Column Mappings
        this.ToTable("MyTable", "database");
        this.Property(t => t.SomeId).HasColumnName("SomeId");
        this.Property(t => t.SomeText).HasColumnName("SomeText");


    }




   }
}

Thank you,


Solution 1:

You need to add your table to your implementation of the DbContext class, e.g.

public class MyDatabaseEntities : DbContext {
    public virtual DbSet<MyTable> MyTable { get; set; }
}

Solution 2:

While rolling back an existing EF Core Data Context back to empty, my migrations wouldn't generate until I removed the ApplicationDbContextModelSnapshot that accompanied the migrations.

This class is auto-generated and needs to align with your current migration level.