简体   繁体   中英

MVC Update-database, Enable-Migrations problems after upgrading to EF6

I have upgraded to EF6 in my MVC application.

When I try Enable-Migrations in the PM console.

No context type was found in the assembly 'Cardsender02'

I have only one project in the solution and as I see it I do have a context.

namespace Cardsender02.Models
{
    public class CardContext : DbContext
    {
        public CardContext()
           : base("DefaultConnection")
        {}

Then I try

Enable-Migrations -ContextTypeName Cardsender02.Models.CardContext

But that gives me

The type 'Cardsender02.Migrations.Configuration' does not inherit from 'System.Data.Entity.Migrations.DbMigrationsConfiguration'. Migrations configuration types must extend from 'System.Data.Entity.Migrations.DbMigrationsConfiguration'.

What to do now?

Configuration class:

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

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

    protected override void Seed(Cardsender02.Models.CardContext context)
    {}
 }}

If you want to upgrade to EF6, please make sure all dependencies are properly upgraded including the assembly, config, and other references.

You can use this command to reinstall properly from Package Manager Console.

Update-Package –reinstall EntityFramework

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM