Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF Core SqLite in-memory no such table?

I configured my ASP.NET Core 2.2 app using UseInMemoryDatabase() and it worked fine. Now I changed it to relational Sqlite in-memory.

Startup.cs

 services.AddDbContext<ApplicationContext>(options => options.UseSqlite("Datasource=file::memory:?cache=shared"));

I use this Sqlite in-memory approach in unit tests and it work good. So decided I want to use the same in-memory Sqlite in my app (to test some things, later when app will be ready I'll create sqlite file on disk). The problem is when I starting my app. I receive erros like SqliteException: SQLite Error 1: 'no such table: USERS'. I debug my repository class and I found that context has table Users. So Sqlite in-memory works fine in unit tests but in real app throws error. Why is that? Thanks for any tips.

enter image description here

like image 825
miuosh Avatar asked Sep 09 '26 11:09

miuosh


1 Answers

Create and apply migrations to your in-memory SQLite database. You'll have to apply them every time the app starts, since the database only exists in memory until the application exits.

like image 91
RickC Avatar answered Sep 12 '26 02:09

RickC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!