威势网络,为您的企业和团队注入互联网活力!
服务热线:138-9741-0341

SQLite Error 1: 'no such table: AspNetUser'.

发布日期:2023/4/6 作者: 浏览:1279

    在用下面的命令重新创建数据库

>   drop-database

> add-migration Init

然后VS自动创建生成迁移类,里面明显可以看到有创建表的语句

         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);
                });
但是 执行完 

>update-database

的时候,发现表里面除了__EFMigrationsHistory 表之外,一个表也没有创建成功,程序还报 SQLite Error 1: 'no such table: AspNetUser'. 的错误。


试了好几遍都不行,以前都是用这三句重新生成的,也没有发现问题。如上图所示,从回文长度来看也不正常。后来经过多次尝试,发现用以下命令代替上面的命令可以成功创建表,也不知道是啥原因

    /*
    PM>Drop-Database
    PM> Add-Migration InitialCreate
    PM> Update-Database
     */


    >add-migration Init -c AppDbContext -o Data/AppDb 

    >Update-Database -Context AppDbContext

把上面的三句换成下面的命令,成功创建数据表。记录一下,也希望帮到别人。


下拉加载更多评论
最新评论
暂无!