Asp.net core - no such table: AspNetUsers

一曲冷凌霜 提交于 2019-12-05 18:29:41

It sounds like you forgot to call update-database in the package manager console. That's what actually applies the migrations you create to your connected database(s).

The other issue may be with how you updated the table name(s). If you edited the migrations directly, it has no way to know that you changed the name at run-time and will still look for the default named tables.

To change the user table name, you want to do something like this in your DB context in the OnModelCreating method:

protected override void OnModelCreating( ModelBuilder builder ) {
    base.OnModelCreating( builder );
    // Customize the ASP.NET Identity model and override the defaults if needed.
    // For example, you can rename the ASP.NET Identity table names and more.
    // Add your customizations after calling base.OnModelCreating(builder);

    builder.Entity<ApplicationUser>() //Use your application user class here
           .ToTable( "ContosoUsers" ); //Set the table name here
}

You'll then want to create a migration to make sure everything is updated by running the following in the package manager console:

add-migration RenamedUserTable

Then run a quick update-database and try again.

I was getting same issue which I fixed by providing table name in OnModelCreating method.

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            string SQLLiteConnectionString = @"Data Source=C:/Projects/ArticlesDB.db";
            optionsBuilder.UseSqlite(SQLLiteConnectionString);             
        }
protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Articles>().ToTable("Articles");
            modelBuilder.Entity<Articles>(entity =>
            {
                entity.Property(e => e.Id).IsRequired();
            });
        }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!