I'm trying to publish a code-first webapp that uses sqlite to Azure. Now, the application is working fine locally. but when I publish, it seems that the database file is not being created properly, and I get the following error:
SqliteException: SQLite Error 1: 'no such table: Blogs'. Microsoft.Data.Sqlite.Interop.MarshalEx.ThrowExceptionForRC(int rc, Sqlite3Handle db)
I am not sure as to why the Blogs table isn't created (and I assume the rest aren't created either).
my ApplicationDbContext.cs
looks like this:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
public ApplicationDbContext()
{
Database.EnsureCreated();
Database.Migrate();
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
}
public DbSet<Publication> Publications { get; set; }
public DbSet<Blog> Blogs { get; set; }
public DbSet<Student> Students { get; set; }
public DbSet<ApplicationUser> ApplicationUser { get; set; }
}
Configuration:
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlite(Configuration.GetConnectionString("DefaultConnection"))
);
}
and DefaultConnection
in appsettings.json
:
"ConnectionStrings": {
"DefaultConnection": "Filename=.\\mydb.sqlite"
},
Furthermore, when I download mydb.sqlite
and open it, its completely empty.