SQLite Working Directory Error with EF Core Web Api
The other day, I was trying to build a simple Web Api using .NET 6. My database of choice when playing around with web api for my students and tutoring, is always SQLite.
SQLite is free. It does not need a dedicated server. More importantly it works flawlessly with Entity Framework.
However, for some reason, many of old projects, have stopped working in the newer versions of .NET.
Now, you can try the following.
You need to install 'Install-Package Microsoft.EntityFrameworkCore.Tools'. Previously, this was not there or was not required.
Yes, EF Core keeps evolving and packages are being split up to make them more portable and slim, I guess.
Set Working Directory manually
So, right then. I think, the core of the problem is that, in the previous versions of .NET, the working directory was being picked up automatically. Now, the place where the database gets created, and where the project looks for the database are two different locations.
More details are available in this online discussion.
You can do the directory thing is like this.
In Solution Explorer, right click the project and then select Properties.
Select the Debug tab in the left pane.
Set Working directory to the project directory.
Save the changes.
After this, you may want to do, the usual, EF core commands.
Add-Migration InitialCreate
Update-Database
That’s all there is to it.
I work as a full time freelance coding tutor. Hire me at UpWork or Fiverr or Stack Overflow. My personal website is here. Find more of my art at Behance and Unsplash. Also, I have a Podcast. Also, I am on substack.