In my Config class, I want to set the check_same_thread to False as below (to avoid the error: sqlalchemy.exc.ProgrammingError: (sqlite3.ProgrammingError) SQLite objects created in a thread can only be used in that same thread. .....)
class Config(object):
#------#
SQLALCHEMY_DATABASE_URI = 'sqlite:///app.db?check_same_thread=False'
#------#
However, in setting up my Config class of the Flask app, I followed Miguel Grinberg's Flask Mega-tutorial and set up the SQLAlchemy database as follows:
class Config(object):
#------#
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \
'sqlite:///'+os.path.join(basedir, 'app.db')
SQLALCHEMY_TRACK_MODIFICATIONS = False
#------#
How do I integrate the set the check_same_thread to False in the above case? Any help or guidance would be highly appreciated.
Thanks!
Actually the answer that worked for my question was:
SQLALCHEMY_DATABASE_URI = (os.environ.get('DATABASE_URL') or \
'sqlite:///'+os.path.join(basedir, 'app.db'))+'?check_same_thread=False'
Note that the '?check_same_thread=False' part should be added to both cases on either side of the or.
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加