Entity Framework Core 2.0 - Add-Migration does not work

Asked

Viewed 1,644 times

3

I am creating a new code-first project. When trying to create Migration, using the command [Add-Migration Initial -Context LogAuditoriaContext] it simply does nothing, creates nothing, makes no mistake, informs nothing:

I’ve tried mapping with FluentAPI so much on the OnModelCreating() as in separate files, the result is the same.

Looking at the Output Window, it shows:

Build: 0 succeeded, 0 failed, 6 up-to-date, 0 skipped

I am using dot.net core 2.0 and C# 7.2.

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui


UPDATE (Solution) With the tips of @Armindo Gomes, I found out that the problem was the connection string, just change the name of LogAuditoria for LogAuditoriaConnection and its references in Startup and LogAuditoriaContext.

inserir a descrição da imagem aqui

  • has already run Enable-Migrations ?

  • https://msdn.microsoft.com/en-us/library/jj193542(v=vs.113). aspx

  • 2

    @Marconciliosouza, Enable-Migrations is obsolete in Entity framework core. Now Add-Migration is used

  • I think, it’s really nice, there’s a dotted green line in the configuration json in the key LogAuditoria I think we’re missing a bar Desktop\SqlExpress should be Desktop\\SqlExpress takes the test!

  • @Leofelipe, true, had not seen that it was core shausa... der a Clean Solution and Compile again.

  • @Virgilionovic, if you ask me, you really should have two bars. but unfortunately it was not the case to solve, but thank you anyway.

  • @Marconcilio Souza, had already made the clean and rebuild, but without success.

  • @Leofelipe, have tried following the steps https://docs.microsoft.com/en-us/aspnet/core/data/ef-mvc/migrations?

  • could you upload the detailed log of VS? https://elbruno.com/2015/01/06/vs2015-howto-show-more-detail-in-a-local-buildin-the-visual-studio-ide/

Show 4 more comments

1 answer

2


Try it this way:

In the archive appsettings.json

"LogAuditoriaConnection": "Server=.\\sqlexpress;Database=LogAuditoria;Trusted_Connection=True;User Id=sa;Password=**********"

In the archive Logauditoriacontext.Cs

public class LogAuditoriaContext : DbContext {

    public LogAuditoriaContext(DbContextOptions<LogAuditoriaContext> options) : base(options) { }

    public DbSet<LogLocation> LogLocation{ get; set; }
    public DbSet<LogRequest> LogRequest { get; set; }
    public DbSet<LogResponse> LogResponse { get; set; }
    public DbSet<Sistema> Sistema { get; set; }

    protected override void OnModelCreating(ModelBuilder builder) {
        base.OnModelCreating(builder);
    }
}

In the archive Startup.Cs

public void ConfigureServices(IServiceCollection services) {
    services.AddDbContext<LogAuditoriaContext>(options => options.UseSqlServer(Configuration.GetConnectionString("LogAuditoriaConnection")));
    // Outros services
    services.AddMvc();
}

On the console of PMC:

add-migration NomeMigration
update-database

Source:

Getting Started with EF Core on ASP.NET Core with a New database

  • 1

    thank you. I discovered that the problem was the connection string, just changing the name from Logauditoria to Logauditoriaconnection and its refections in Startup and Logauditoriacontext. Thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.