© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
6 replies
alkasel#159

EF Core Add-Migration only includes key columns [Answered]

Hi,
I'm using EF Core for the first time. When I run Add-Migrations command, the migration classes are generated, but in every table only primary keys column(s) are included.

I have a couple of classes, e.g.
[Table("Transl", Schema = "public")]
public class Transl
{
    [Required]
    public string Symbol;

    [Required]
    public string LanguageIso;

    [Required]
    public string Translation;

    public Transl() {}
}
[Table("Transl", Schema = "public")]
public class Transl
{
    [Required]
    public string Symbol;

    [Required]
    public string LanguageIso;

    [Required]
    public string Translation;

    public Transl() {}
}


And I have the following ApplicationDbContext
public class ApplicationDbContext : DbContext
{
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { }

    public DbSet<Lang> Lang { get; set; }
    public DbSet<Transl> Transl { get; set; }

    protected override void OnModelCreating(ModelBuilder builder) {
        base.OnModelCreating(builder);
        builder.Entity<Transl>().HasKey(x => new { x.Symbol, x.LanguageIso });

    }
}
public class ApplicationDbContext : DbContext
{
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { }

    public DbSet<Lang> Lang { get; set; }
    public DbSet<Transl> Transl { get; set; }

    protected override void OnModelCreating(ModelBuilder builder) {
        base.OnModelCreating(builder);
        builder.Entity<Transl>().HasKey(x => new { x.Symbol, x.LanguageIso });

    }
}


And in Program.cs I have
        _builder.Services.AddDbContext<ApplicationDbContext>(options =>
            options.UseNpgsql(_builder.Configuration.GetConnectionString("DefaultConnection")));
        _builder.Services.AddDbContext<ApplicationDbContext>(options =>
            options.UseNpgsql(_builder.Configuration.GetConnectionString("DefaultConnection")));


If I run Update-Database, the database is successfully updated, but only colums representing a primary key are included in the table.

Add-Migration produces no error, the only line a bit strange is
No referenced design-time services were found
No referenced design-time services were found
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ EF Core Add Migration issue
C#CC# / help
4y ago
Migration issues -EF core.
C#CC# / help
16mo ago
EF-Core data reference [Answered]
C#CC# / help
4y ago