Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable migration in SQLite using EF

I have stuck in problem. I am writing a code for windows desktop application and I have to use sqlite as a database. I have successfully installed system.data.sqlite and entity framework from nuget package. I have also created my DbContext class. Now problem is that as soon as I tried to run my code an exception comes whose inner message is

{"SQLite Error 1: 'no such table: TimeSheet'"}.

This means your table TimeSheet does not exist in database. Plz tell me how to create table in sqlite using entity framework or how to enable migrations.

like image 252
habib Avatar asked Aug 31 '16 10:08

habib


People also ask

How do I apply ef core migration?

Migrations are enabled by default in EF Core. They are managed by executing commands. If you have Visual Studio, you can use the Package Manager Console (PMC) to manage migrations. Alternatively, you can use a command line tool to execute Entity Framework CLI commands to create a migration.

How do I run down my ef migration?

Delete your Migrations folder. Create a new migration and generate a SQL script for it. In your database, delete all rows from the migrations history table. Insert a single row into the migrations history, to record that the first migration has already been applied, since your tables are already there.


2 Answers

Unlike MS SQL Server, as default, the free Sqlite driver from system.data.sqlite doesn’t support Migration.So you can’t create a new database from code.You have to manually create it.

For that you can use SQLite Manager add-on for Firefox.

Here is the link : SQLite Manager

Or you can use SQL Server Compact/SQLite Toolbox where @ErikEJ suggested below.

like image 173
Sampath Avatar answered Oct 11 '22 13:10

Sampath


There are some implementations of migration for SQLite.

https://github.com/bubibubi/db2ef6migrations is based on the new EF6 migration interface but it has some restrictions. You can download it from Nuget searching for System.Data.SQLite.EF6.Migrations

like image 38
bubi Avatar answered Oct 11 '22 12:10

bubi