1

I have different DbContexts that connects to different database. My first two DbContexts works fine when adding migration but the last DbContext (FinalPmisDbContext) that I have added couldn't add a migration. I have tried these two commands in the PM

Enable-Migrations -ContextTypeName SosaPmisApi.Models.FinalPmisDbContext -Force

this is the result I get:

Checking if the context targets an existing database...
Code First Migrations enabled for project SosaPmisApi.

Then I run this command:

add-migration -ConfigurationTypeName SosaPmisApi.Migrations.FinalPmisDbContext.Configuration "AddedPropertySoa"

But I get this error: The migrations configuration type 'SosaPmisApi.Migrations.FinalPmisDbContext.Configuration' was not be found in the assembly 'SosaPmisApi'.

This is my DbContext:

using SosaPmisApi.Models.FinalCurtain;
using System.Data.Entity;

namespace SosaPmisApi.Models
{
    public class FinalPmisDbContext : DbContext
    {
        public FinalPmisDbContext() : base("RevisionConnection") { }

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

EDIT I can see a Configuration.cs that has this..

namespace SosaPmisApi.Migrations
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Migrations;
    using System.Linq;

    internal sealed class Configuration : DbMigrationsConfiguration<SosaPmisApi.Models.FinalPmisDbContext>
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = false;
        }

        protected override void Seed(SosaPmisApi.Models.FinalPmisDbContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method 
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //
        }
    }
}
stack questions
  • 862
  • 2
  • 15
  • 29

0 Answers0