gpt4 book ai didi

sqlite - EF Core 更新数据库抛出 System.NullReferenceException

转载 作者:行者123 更新时间:2023-12-05 08:25:59 29 4
gpt4 key购买 nike

我正在尝试使用 EF.Core 测试制作 SQLite 数据库。尽管我尽了一切努力让它工作,但它仍然没有按预期工作,我不知道为什么。 Add-Migration 命令工作正常,但是当我尝试 Update-DataBase 时它抛出 System.NullReferenceException。任何人都知道为什么会这样?您可以在下面看到代码和异常。

public class TestModel
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public string Name { get; set; }
}
private const string ConnectionString = "Data Source = AutoHome.db";

public DbSet<TestModel> testModels { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
options.UseSqlite(ConnectionString);
base.OnConfiguring(options);
}

PM> Update-DataBase Build started... Build succeeded. System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.Data.Sqlite.SqliteConnection.Open() at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnection(Boolean errorsExpected) at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected) at Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal.SqliteDatabaseCreator.Exists() at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.Exists() at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration) at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String contextType) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_0.<.ctor>b__0() at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action) Object reference not set to an instance of an object. PM>

最佳答案

这似乎是 Microsoft.Data.Sqlite.Core 的问题。我刚刚添加了一个引用 Microsoft.Data.Sqlite,现在一切正常。

OBS!!!

关于这个 GitHub/EF/Issues 已经有一个开放的工单

关于sqlite - EF Core 更新数据库抛出 System.NullReferenceException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59186616/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com