E
E
EElliiaann2020-06-20 15:07:36
C++ / C#
EElliiaann, 2020-06-20 15:07:36

The database is not created (ASP.NET Core + EF Core), what's the problem?

in appsettings

"ConnectionStrings": {
    "DefaultConnection": "Server=(LocalDb)\\MSSQLLocalDB; Database=test; Trusted_Connection=True;"
  },


In startup
public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();

            string connection = Configuration.GetConnectionString("DefaultConnection");
            services.AddDbContext<AppDbContext>(x => x.UseSqlServer(connection));
        }


Context:

public DbSet<People> Peoples { get; set; }

        public AppDbContext(DbContextOptions<AppDbContext> options) 
            : base(options) 
        {
            Database.EnsureCreated();
        }


Should the database be created on the first run? This is not happening.
Nothing else changed or added.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Korotenko, 2020-06-20
@firedragon

What's wrong? However, it universally helps to type in the package console Add-migration initial
Update-database

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question