'没有这样的表:__EFMigrationsHistory'

问题描述 投票:0回答:1

我是 .net core 的新手。当我在 VS code 终端中写入时

dotnet ef database update

我收到以下消息。

Build started...
Build succeeded.
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
  Executed DbCommand (33ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
  SELECT COUNT(*) FROM "sqlite_master" WHERE "name" = '__EFMigrationsHistory' AND "type" = 'table';
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
  Executed DbCommand (1ms) [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']
  SELECT COUNT(*) FROM "sqlite_master" WHERE "name" = '__EFMigrationsHistory' AND "type" = 'table';
info: Microsoft.EntityFrameworkCore.Migrations[20402]
Applying migration '20230820051454_InitialCreate'.
Applying migration '20230820051454_InitialCreate'.
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
  Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
  CREATE TABLE "Products" (
      "Id" INTEGER NOT NULL CONSTRAINT "PK_Products" PRIMARY KEY AUTOINCREMENT,
      "Name" INTEGER NOT NULL
  );
fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
  Failed executing DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
  INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
  VALUES ('20230820051454_InitialCreate', '7.0.10');
Failed executing DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20230820051454_InitialCreate', '7.0.10');
Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 1: 'no such table: __EFMigrationsHistory'.
at Microsoft.Data.Sqlite.SqliteException.ThrowExceptionForRC(Int32 rc, sqlite3 db)
at Microsoft.Data.Sqlite.SqliteCommand.PrepareAndEnumerateStatements(Stopwatch timer)+MoveNext()
at Microsoft.Data.Sqlite.SqliteCommand.GetStatements(Stopwatch timer)+MoveNext()
at Microsoft.Data.Sqlite.SqliteDataReader.NextResult()
at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader(CommandBehavior behavior)
at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader()
at Microsoft.Data.Sqlite.SqliteCommand.ExecuteNonQuery()
at    Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteNonQuery(RelationalCommandParameterObject parameterObject)
at Microsoft.EntityFrameworkCore.Migrations.MigrationCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.ExecuteNonQuery(IEnumerable`1 migrationCommands, IRelationalConnection connection)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String connectionString, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String connectionString, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
SQLite Error 1: 'no such table: __EFMigrationsHistory'.

我在appsettings.development.jason中有以下代码

{
"Logging": {
  "LogLevel": {
  "Default": "Information",
  "Microsoft.AspNetCore": "Information"
  }
},
"ConnectionStrings": {
"DefaultConnection": "Data Source=skinet.db"
 }
}

在 StoreContext.cs 文件中有

namespace API.Data
{
 public class StoreContext:DbContext
{

    public StoreContext(DbContextOptions options) : base(options)
    {
    }

    public DbSet<Product> Products { get; set; }
    
}
}

并且在Program.cs文件中有

builder.Services.AddDbContext<StoreContext> (opt=>
{

opt.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection"));

});

有没有人可以在这方面帮助我?谢谢。

我是 .net core 的新手。当我在 VS code 终端中写入时

dotnet ef database update

我收到以下消息。

Build started...
Build succeeded.
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
  Executed DbCommand (33ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
  SELECT COUNT(*) FROM "sqlite_master" WHERE "name" = '__EFMigrationsHistory' AND "type" = 'table';
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
  Executed DbCommand (1ms) [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']
  SELECT COUNT(*) FROM "sqlite_master" WHERE "name" = '__EFMigrationsHistory' AND "type" = 'table';
info: Microsoft.EntityFrameworkCore.Migrations[20402]
Applying migration '20230820051454_InitialCreate'.
Applying migration '20230820051454_InitialCreate'.
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
  Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
  CREATE TABLE "Products" (
      "Id" INTEGER NOT NULL CONSTRAINT "PK_Products" PRIMARY KEY AUTOINCREMENT,
      "Name" INTEGER NOT NULL
  );
fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
  ................


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

我在appsettings.development.jason中有以下代码

{
"Logging": {
  "LogLevel": {
  "Default": "Information",
  "Microsoft.AspNetCore": "Information"
  }
},
"ConnectionStrings": {
"DefaultConnection": "Data Source=skinet.db"
 }
}

在 StoreContext.cs 文件中有

namespace API.Data
{
 public class StoreContext:DbContext
{

    public StoreContext(DbContextOptions options) : base(options)
    {
    }

    public DbSet<Product> Products { get; set; }
    
}
}

并且在Program.cs文件中有

builder.Services.AddDbContext<StoreContext> (opt=>
{

opt.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection"));

});

如何创建_EFmigrationHistory或解决问题?有没有人可以在这方面帮助我?谢谢。

.net angular sqlite core
1个回答
0
投票

就我而言,这是我在从开发调试到生产时更改的调试启动配置文件值。我没有在生产应用程序设置文件中指定连接字符串设置。我刚刚将 ASPNETCORE_ENVIRONMENT 从生产更改为开发。

将其留在这里以防万一有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.