mehmetserif
mehmetserif

Reputation: 1227

SQLite CreateDatabase not supported error

I'm using Entity Framework 4.2 CF with SQLite, but when i try to launch the application i got "CreateDatabase is not supported by the provider" error. This is my model mapping:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            #region NewsMapping

            modelBuilder.Entity<News>().ToTable("news");
            modelBuilder.Entity<News>().HasKey(x => x.Id).Property(x => x.Id).HasColumnName("ID").HasColumnOrder(0);
            modelBuilder.Entity<News>().Property(x => x.Status).HasColumnName("STATUS");
            modelBuilder.Entity<News>().Property(x => x.NewsTitle).HasColumnName("NEWS_TITLE");
            modelBuilder.Entity<News>().Property(x => x.Content).HasColumnName("CONTENT_1");
            modelBuilder.Entity<News>().Property(x => x.IsImportant).HasColumnName("IS_IMPORTANT");
            modelBuilder.Entity<News>().Property(x => x.OrderNumber).HasColumnName("ORDER_NUMBER");
            modelBuilder.Entity<News>().Property(x => x.CreateDate).HasColumnName("CREATE_DATE");
            #endregion

            base.OnModelCreating(modelBuilder);

        }

What is wrong in this code?

Thanks

Upvotes: 4

Views: 11316

Answers (4)

AJ Dhaliwal
AJ Dhaliwal

Reputation: 721

I got this error for EF 6.1.3 and System.Data.Sqlite 1.0.103 because I did not specify the location of the database file properly in my web.config file.

To fix the problem I moved the database file to App_Data and changed my connection string to connectionString="data source=|DataDirectory|databaseName;Version=3;"

Upvotes: 5

Ben
Ben

Reputation: 501

As been because of the wrong path of my sqlitedb for me in the web.config, as simple and stupid that annoying.

Upvotes: 0

mehmetserif
mehmetserif

Reputation: 1227

Ok i found the solution, the provider doesn't support "Database Creation", so i had to initialize it empty:

public EkosContext()
        {
            Database.SetInitializer<EkosContext>(null);
        } 

Upvotes: 4

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364249

Nothing is wrong in the code. The error says exactly what is going on. Your EF provider for SQLite (System.Data.SQLite) doesn't provide database creation so you must create database and all tables manually before you launch the application.

Upvotes: 9

Related Questions