SQLite Error 1: 'no such table: AspNetUser'.
在用下面的命令重新創(chuàng)建數(shù)據(jù)庫
> drop-database
> add-migration Init
然后VS自動創(chuàng)建生成遷移類,里面明顯可以看到有創(chuàng)建表的語句
migrationBuilder.CreateTable(
name: "AspNetUsers",
columns: table => new
{
Id = table.Column<string>(type: "TEXT", nullable: false),
Sex = table.Column<string>(type: "TEXT", maxLength: 1, nullable: true),
NickName = table.Column<string>(type: "TEXT", maxLength: 10, nullable: true),
IsLocal = table.Column<bool>(type: "INTEGER", nullable: false),
IP = table.Column<string>(type: "TEXT", maxLength: 46, nullable: false),
RegTime = table.Column<DateTime>(type: "TEXT", nullable: false),
UserName = table.Column<string>(type: "TEXT", maxLength: 256, nullable: true),
NormalizedUserName = table.Column<string>(type: "TEXT", maxLength: 256, nullable: true),
Email = table.Column<string>(type: "TEXT", maxLength: 256, nullable: true),
NormalizedEmail = table.Column<string>(type: "TEXT", maxLength: 256, nullable: true),
EmailConfirmed = table.Column<bool>(type: "INTEGER", nullable: false),
PasswordHash = table.Column<string>(type: "TEXT", nullable: true),
SecurityStamp = table.Column<string>(type: "TEXT", nullable: true),
ConcurrencyStamp = table.Column<string>(type: "TEXT", nullable: true),
PhoneNumber = table.Column<string>(type: "TEXT", nullable: true),
PhoneNumberConfirmed = table.Column<bool>(type: "INTEGER", nullable: false),
TwoFactorEnabled = table.Column<bool>(type: "INTEGER", nullable: false),
LockoutEnd = table.Column<DateTimeOffset>(type: "TEXT", nullable: true),
LockoutEnabled = table.Column<bool>(type: "INTEGER", nullable: false),
AccessFailedCount = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUsers", x => x.Id);
});
但是 執(zhí)行完
>update-database
的時候,發(fā)現(xiàn)表里面除了__EFMigrationsHistory 表之外,一個表也沒有創(chuàng)建成功,程序還報 SQLite Error 1: 'no such table: AspNetUser'. 的錯誤。
試了好幾遍都不行,以前都是用這三句重新生成的,也沒有發(fā)現(xiàn)問題。如上圖所示,從回文長度來看也不正常。后來經(jīng)過多次嘗試,發(fā)現(xiàn)用以下命令代替上面的命令可以成功創(chuàng)建表,也不知道是啥原因
/*
PM>Drop-Database
PM> Add-Migration InitialCreate
PM> Update-Database
*/
>add-migration Init -c AppDbContext -o Data/AppDb
>Update-Database -Context AppDbContext
