Flask-sqlalchemy 's session problem?

according to the book, this error will be reported all the time, which probably means that this error can only be used in the same thread, right? Do you want to use creat_scoped_session? please give me some advice. Thank you!

sqlalchemy.exc.ProgrammingError: (sqlite3.ProgrammingError) SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 139878844028672 and this is thread id 139878951810816 (Background on this error at: http://sqlalche.me/e/f405)


change the uri of the database to this:

SQLALCHEMY_DATABASE_URI = 'sqlite:///xxxx.db?check_same_thread=False'

there is a paid video on Mu course net. If you need to see my home page


if you configure

in your flask configuration file config.py
SQLALCHEMY_TRACK_MODIFICATIONS = True
SQLALCHEMY_COMMIT_ON_TEARDOWN = True

then you no longer need to explicitly write db.session.commit () in the program.

Does

mean that the object is used across threads? Can you tell me the complete business scenario?


I don't know your complete business scenario, but if you cross threads, you usually need to pass app_context.

 
app_context = flask.current_app.app_context()

-sharp app_context
with app_context:
  ........
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b2b0ca-4e6ce.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b2b0ca-4e6ce.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?