Maui‘SQLite错误1:’没有这样的表:播放器‘’

toiithl6  于 2022-11-15  发布在  SQLite
关注(0)|答案(1)|浏览(166)

当我想要在数据库中添加字段时,它会告诉我"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

5f0d552i

5f0d552i1#

为了解决这个问题,我删除了以下评论:this.Database.EnsureCreated();

相关问题