Using SQLAlchemy session from Flask raises “SQLite objects created in a thread can only be used in that same thread”

Taking a hint from this SO answer I searched SA docs and found out you can do this: engine = create_engine(‘sqlite:////var/www/homepage/blog.db?check_same_thread=False’) scoped_session wasn’t really suitable in my case since Flask-SQLAlchemy only takes a connection string argument: from flask import Flask from flask_sqlalchemy import SQLAlchemy class Config(object): SQLALCHEMY_DATABASE_URI = ‘sqlite:///app.db?check_same_thread=False’ db = SQLAlchemy() def create_app(): app.config.from_object(Config) … Read more

SQLite and concurrency [closed]

I try to avoid emotive replies and hyperbole but I am truly astonished at the lack of knowledge about sqlite displayed on this page. Different database implementations serve different needs and from the operational specs you provide, sqlite3 seems ideal for your needs. To elaborate: sqlite3 is fully ACID compliant, meaning it ensures atomic commits, … Read more

Bulk insert huge data into SQLite using Python

Since this is the top result on a Google search I thought it might be nice to update this question. From the python sqlite docs you can use import sqlite3 persons = [ (“Hugo”, “Boss”), (“Calvin”, “Klein”) ] con = sqlite3.connect(“:memory:”) # Create the table con.execute(“create table person(firstname, lastname)”) # Fill the table con.executemany(“insert into … Read more

Unable to create an object of type ‘MyContext’. For the different patterns supported at design time

I Resolved this by just adding a plain constructor to my Context public class DataContext : DbContext { public DataContext() { } public DataContext(DbContextOptions options) : base(options) { } protected override void OnConfiguring(DbContextOptionsBuilder options) { if (!options.IsConfigured) { options.UseSqlServer(“A FALLBACK CONNECTION STRING”); } } protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); } }