EF migration not creating table

Issue

enter image description here

I’m very inexperienced with EF and I read that model files is mainly where the EF migration will find database items to add/drop on migration.

We took a client’s code to work on for a friend and adding new columns has been easy peasy however now I am adding a table and I cannot get it to migrate over. I tried with only a model file for the table. Then I tried with all relevant BE files such as repository.cs, services.cs, commands.cs, queries.cs, models.cs, data (screen shot to show full file paths).

What am I missing? Everything is spelled correctly and I even thought of just manually typing it into the up/down area on the migration and then updating the designer file and snapshot. But I still got an error. There are no errors visible in the Terminal .

Here is the model file code:

using System.ComponentModel.DataAnnotations.Schema;
using ABC.Express.Core.Attributes;

namespace ABC.Express.Domain.Models
{
    [Table("builder_preferences")] //follows naming convention of other files
    public class BuilderPreferences : BaseEntity
    {
        public long BuilderId { get; set; }
        public long GroupId {get; set;}

        public static BuilderPreferences Create(long organizationId, long builderId, long groupId)
        {
            return new BuilderPreferences
            {
                OrganizationId = organizationId, //this is in the BASEENTITY
                BuilderId = builderId,
                GroupId = groupId
            };
        }
    }
}

Solution

Ensure that you have added the BuilderPreferences entity to your DbContext’s DbSet. In your DbContext class, you should have something like this:

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

Answered By – Antoan Elenkov

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published