当我想要在数据库中添加字段时,它会告诉我"SQLite Error 1: 'no such table: Players'."
,但只要我一查看我的数据库,就会看到一个PLAYS表。我怎么才能解决这个问题呢?
以下是要保存在数据库中的文件
游戏DbContext
namespace MereTuBois.Data
{
public class GameDbContext : DbContext
{
private readonly IDeviceService _deviceService;
public DbSet<Players> Players { get; set; }
public DbSet<Session> Sessions { get; set; }
public GameDbContext(IDeviceService deviceService)
{
_deviceService = deviceService;
//this.Database.EnsureCreated();
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
string dbPath = Path.Combine(_deviceService?.AppDataDirectory ?? ".", "mereTubois.db3");
optionsBuilder.UseSqlite($"Filename={dbPath}");
}
}
public class HistoryContextFacotry : IDesignTimeDbContextFactory<GameDbContext>
{
public GameDbContext CreateDbContext(string[] args)
{
return new GameDbContext(null);
}
}
}
迁移链接:https://github.com/Waterlok653/MIgration
1条答案
按热度按时间5f0d552i1#
为了解决这个问题,我删除了以下评论:
this.Database.EnsureCreated();