I'm quite new to Entity Framework Core, and mostly I learn by myself from MSDN website. Currently I'm learning Identity
Though I'm using dotnet core 3.0, but current project is using dotnet core 2.2, so I choose 2.2 as a start point of Identity learning.
Since I want to customize Identity, I used the following step to start this new project:
Create a new project, choose "ASP.NET Core Web Application", ".NET Core", "ASP.NET Core 2.2", "Web Application (Model-View-Controller), change "Authentication", using "Individual User Accounts"
Update "appsettings.json" with external database "ConnectionStrings" content
- In PMC, use command "Update-Database" to update database
- Database and all Identity tables are created, project is run correctly
- add migration to update table and column through command "Add-migration 1stmigration"
- Update Up() and Down() functions:
public partial class _1stmigration : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameTable(
name: "AspNetUsers",
newName: "Users");
migrationBuilder.RenameColumn(
name: "Email",
table: "Users",
newName: "EmailAddress");
migrationBuilder.DropIndex(
name: "UserNameIndex",
table: "Users");
migrationBuilder.DropColumn(
name: "NormalizedUserName",
table: "Users");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "NormalizedUserName",
table: "Users");
migrationBuilder.CreateIndex(
name: "UserNameIndex",
table: "Users",
column: "NormalizedUserName");
migrationBuilder.RenameColumn(
name: "EmailAddress",
table: "Users",
newName: "Email");
migrationBuilder.RenameTable(
name: "Users",
newName: "AspNetUsers");
}
}
Code is to change default "AspNetUsers" table name to "Users", and change "Email" column to "EmailAddress", and delete "NormalizedUserName" column and "UserNameIndex" index. 6. run command "Update-Database" to update Database table. Database table/column are updated as what's needed, but when running the project to register a new user, it returns error:
SqlException: Invalid object name 'AspNetUsers'.
System.Data.SqlClient.SqlCommand+<>c.b__122_0(Task result)
I checked the snapshot file in "Migrations" folder, finding the code creating database table is not changed. My question is: 1. When the snapshot file "ApplicationDbContextModelSnapshot.cs" is updated, I thought it should be updated when executing "Add-migration" command after Down() and Up() functions have the updated code 2. How to make it work till the previous steps are done?
Thanks for the help.