Hobospy
Hobospy

Reputation: 51

Why do I get Object reference not set to an instance of an object when running Update-Database

First time working with entity framework, I've been testing with an in memory database which has been working fine but wanted to start working on a persistent database using sqlite.

I've got the model and context created, when I run Add-Migration in the Package Manager Console it seems to work fine but when I then run the Update-Database function I always get a 'Object reference not set to an instance of an object' error but I can't work out why, any help really appreciated, been searching around for a while and can't see anything.

Screenshot of the reported error

I've got four model classes and the context class so not sure I can include all the code snippets here but happy to if folk think it's needed to get anywhere.

Thanks.

Upvotes: 0

Views: 814

Answers (1)

Hobospy
Hobospy

Reputation: 51

OK so I found out what the issue was. The "Object reference not set to an instance of an object" in this case was due to the fact that I didn't have a reference to Microsoft.EntityFrameworkCore.Sqlite. I did have a reference to Microsoft.EntityFrameworkCore.Sqlite.Core which is what allowed the project to build OK but apparently this is required for the Update-Database call.

Also for anyone else needing to take a step back and just confirm they aren't going crazy, this is a good website describing what is needed. I used this just to confirm everything worked OK and I hadn't missed something (which I obviously had).

TL:DR - Make sure you have a reference to Microsoft.EntityFrameworkCore.Sqlite

Upvotes: 1

Related Questions