ASP.NET 5, EF 7 and SQLite - SQLite Error 1: 'no such table: Blog'

I did this and was still having trouble loading the database. I added the following code in the constructor for the database context: Database.EnsureCreated();


Now my context file looks like this: BoardGameDBContextFile

It created a new database on my new Azure hosting site, so if you have a lot of existing data to migrate, this won't work. It worked for me so figured I'd share.


It is very likely the database actually being opened by EF is not the file you are opening in DB Browser. SQLite use the process current working directory, which if launched in IIS or other servers, can be a different folder than your source code directory. (See issues https://github.com/aspnet/Microsoft.Data.Sqlite/issues/132 and https://github.com/aspnet/Microsoft.Data.Sqlite/issues/55).

To ensure your db file is in the right place, use an absolute path. Example:

public class Startup
{
    private IApplicationEnvironment _appEnv;

    public Startup(IApplicationEnvironment appEnv)
    {
        _appEnv = appEnv;
    }
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddEntityFramework()
            .AddSqlite()
            .AddDbContext<MyContext>(
                options => { options.UseSqlite($"Data Source={_appEnv.ApplicationBasePath}/data.db"); });
    }
}

Taken from EF Core documentation...

Run from Visual Studio

To run this sample from Visual Studio, you must set the working directory manually to be the root of the project. Ifyou don't set the working directory, the following Microsoft.Data.Sqlite.SqliteException is thrown: SQLite Error 1: 'no such table: Blogs'.

To set the working directory:

  • 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.