Entity Framework Core 2.0 - Add-Migration does not work

3

I'm creating a new code-first project. When trying to create the migration, using the [Add-Migration Initial -Context LogAuditoriaContext] command it simply does nothing, does not create, does not give error, does not report anything:

I have tried to map with FluentAPI both in OnModelCreating () and 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'm using dot.net core 2.0 and C # 7.2.

UPDATEWiththetipsof@ArmindoGomes,Iwasabletodiscoverthattheproblemwastheconnectionstring,justchangethenameofLogAuditoriatoLogAuditoriaConnectionanditsreferencesinStartupandLogAuditoriaContext.

    
asked by anonymous 27.12.2017 / 14:43

1 answer

1

Try this:

In the appsettings.json

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

In the 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 Startup.cs

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

In the PMC console :

add-migration NomeMigration
update-database

Source:

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

    
28.12.2017 / 03:45