Home > OS >  MAUI 'SQLite Error 1: 'no such table: Players'.'
MAUI 'SQLite Error 1: 'no such table: Players'.'

Time:09-07

when i want to add fields in the database it tells me "SQLite Error 1: 'no such table: Players'." but as soon as i look at my database there is a players table. how can i solve this problem?

Here are the files for saving in the DB

GameDbContext

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);
        }
    }
}

link to the migration : https://github.com/Waterlok653/MIgration

CodePudding user response:

to solve the problem I have removed the following comment : this.Database.EnsureCreated();

  • Related