2

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 Answer 1

12

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

Sign up to request clarification or add additional context in comments.

2 Comments

Worked for me too
Just wanted to add that your problems might not end there. After troubleshooting further and further I ran into this issue: SQLite does not support this migration operation ('DropColumnOperation'). For more information, see go.microsoft.com/fwlink/?LinkId=723262 - which basically means Migrations aren't fully supported or at least compatible to MSSQL unless you tend to drop columns from time to time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.