错误“未应用迁移。数据库已经是最新的“

moh*_*ani 5 c# asp.net sqlite asp.net-core razor-pages

我正在使用 razor 页面和 EF 与 SQLite 构建一个 Web 应用程序。我正在 Linux 下使用 CORE SDK 进行开发。

添加后初始迁移没有问题dotnet ef migrations add InitialCreate。当我更新数据库时,我收到一条消息,指出未应用迁移。数据库已经是最新的了...

当我使用 SQLite 命令解释器(或运行应用程序)检查数据库时,除了空的迁移历史表之外,数据库不包含任何表。__EFMigrationsHistory

我运行 dotnet ef migrations add 时收到的信息消息

info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
User profile is available. Using '/home/vagrant/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
Entity Framework Core 2.0.1-rtm-125 initialized 'AgentContext' using provider 'Microsoft.EntityFrameworkCore.Sqlite' with options: None
Done. To undo this action, use 'ef migrations remove
Run Code Online (Sandbox Code Playgroud)

运行 dotnet ef 数据库更新时收到的输出消息。

info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
User profile is available. Using '/home/vagrant/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
Entity Framework Core 2.0.1-rtm-125 initialized 'AgentContext' using provider 'Microsoft.EntityFrameworkCore.Sqlite' with options: None
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (11ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
PRAGMA foreign_keys=ON;
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
PRAGMA foreign_keys=ON;
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (6ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE "__EFMigrationsHistory" (
"MigrationId" TEXT NOT NULL CONSTRAINT "PK___EFMigrationsHistory" PRIMARY KEY,
"ProductVersion" TEXT NOT NULL
);
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
PRAGMA foreign_keys=ON;
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
PRAGMA foreign_keys=ON;
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT COUNT(*) FROM "sqlite_master" WHERE "name" = '__EFMigrationsHistory' AND "type" = 'table';
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
PRAGMA foreign_keys=ON;
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (3ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT "MigrationId", "ProductVersion"
FROM "__EFMigrationsHistory"
ORDER BY "MigrationId";
info: Microsoft.EntityFrameworkCore.Migrations[20405]
No migrations were applied. The database is already up to date.
No migrations were applied. The database is already up to date.
Done.
Run Code Online (Sandbox Code Playgroud)

数据库上下文:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;

namespace Archive.Models
{
    public class AgentContext : DbContext
    {
        public AgentContext (DbContextOptions<AgentContext> options)
            : base(options)
        {
        }

        public DbSet<Agent> Agent  { get; set; }
    }
}
Run Code Online (Sandbox Code Playgroud)

该模型

using System;

namespace Archive.Models
{
    public class Agent
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public string Departement { get; set; }
    }
}
Run Code Online (Sandbox Code Playgroud)

我尝试手动删除迁移并重新开始,但问题仍然存在。

整个代码