EF Core Update-Database throws System.NullReferenceException

entity-framework-core sqlite

Question

I'm trying to test making SQLite database using EF.Core. Despite all my effort to get it work, it still not working as intended and i don't know why. The Add-Migration command works ok but then when i try to Update-DataBase it throws System.NullReferenceException. Anyone has an idea why is that? Below you can see the code and the exception.

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>

1
0
12/5/2019 5:13:19 PM

Popular Answer

It seems that it is an issue with Microsoft.Data.Sqlite.Core. I just added a reference Microsoft.Data.Sqlite and everything works right now.

OBS!!!

There is already an open ticket about this GitHub/EF/Issues

7
12/5/2019 9:16:10 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow