c# - sqlite on .net core publish to azure fails -
i'm trying publish code-first webapp uses sqlite azure. now, application working fine locally. when publish, seems database file not being created properly, , following error:
sqliteexception: sqlite error 1: 'no such table: blogs'. microsoft.data.sqlite.interop.marshalex.throwexceptionforrc(int rc, sqlite3handle db)
i not sure why blogs table isn't created (and assume rest aren't created either).
my applicationdbcontext.cs
looks 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 download mydb.sqlite
, open it, empty.
@tseng instinct ensurecreated
right. ended solving clearing constructor , adding end of configure
method in startup.cs
var servicescopefactory = app.applicationservices.getrequiredservice<iservicescopefactory>() using (var servicescope = servicescopefactory.createscope()) { var dbcontext = servicescope.serviceprovider.getservice<applicationdbcontext>(); dbcontext.database.ensurecreated(); }
i found answer here
Comments
Post a Comment