SQLite + EF6 "DeleteDatabase is not supported by the provider."

ef-code-first entity-framework entity-framework-6 sqlite


Before I begin, existing questions here and here do not solve my problem.

I am using SQLite with EF6, with package SQLite.CodeFirst used to generate my db schema as required. I am running unit tests on my repository class which uses the DBContext on the backend, but the database needs to be cleaned up before running each test such that subsequent tests are not corrupted.

My problem is that when I call dbContext.Database.Delete() I get the following exception:

System.Data.Entity.Core.ProviderIncompatibleException was unhandled by user code
Message=DeleteDatabase is not supported by the provider.

I want to avoid trying to having to discover the location of the database and deleting it from disk as the location varies depending on application. Has anybody got any suggestions?

Here are excerpts of relevant parts of my code:


    <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />

  <add name="EngineDataContext_LocalDb" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=Engine.DataModel.EngineDataContext;MultipleActiveResultSets=True;Integrated Security=True;App=EntityFramework" providerName="System.Data.SqlClient" />
  <add name="EngineDataContext_SQLServer" connectionString="Data Source=.;Initial Catalog=Engine.DataModel.EngineDataContext;MultipleActiveResultSets=True;Integrated Security=True;" providerName="System.Data.SqlClient" />
  <add name="EngineDataContext_SQLite" connectionString="Data Source=.\database.sqlite" providerName="System.Data.SQLite" />

    <remove invariant="System.Data.SQLite.EF6" />
    <add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
    <remove invariant="System.Data.SQLite" />
    <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />

Data context

public class EngineDataContext : DbContext
    public EngineDataContext()
        : base("name=EngineDataContext_SQLite")

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
        var sqliteConnectionInitializer = new SqliteDropCreateDatabaseAlways<EngineDataContext>(modelBuilder);


public class SqliteRepository
    private readonly EngineDataContext _dataContext;

    public SqliteRepository(EngineDataContext dataContext)
        _dataContext = dataContext;

    public void DropCreateDatabase()
        _dataContext.Database.Delete(); // FAIL
5/23/2017 11:45:43 AM

Popular Answer

It means that the System.data.Sqlite EF provider does not implement the Deletedatabase method (part of Migrations, which is not implemented either). The Devart provider (not free) adds proper support: https://www.devart.com/dotconnect/sqlite/features.html#ef

12/9/2016 2:09:37 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow