In Flask-SQLAlchemy: How do I set check_same_thread=False in config.py?

AviS

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!

AviS

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]

編集
0

コメントを追加

0

関連記事

分類Dev

Flaskの場合-SQLAlchemy:config.pyでcheck_same_thread = Falseを設定するにはどうすればよいですか?

分類Dev

How do I make SQLAlchemy set values for a foreign key by passing a related entity in the constructor?

分類Dev

how to set config before import in pytest conftest.py?

分類Dev

How do I set a value for a hidden field in a Flask form, using wtf.quick_form?

分類Dev

how do I load image in python flask?

分類Dev

How do I install the request class in Flask?

分類Dev

Flask-SQLAlchemy set relationship default value

分類Dev

How do I check if a set of commands are executed on startup?

分類Dev

I have a check constraint on my SQL server, how do i set a validation for the Check Constraint in c#?

分類Dev

Sequelize: How do I use the non-dev config?

分類Dev

How do I transform this element in my Web.config?

分類Dev

How do I find the Sitecore Rocks (Hard Rock) Service config?

分類Dev

how do i load modules and files in the intern config module?

分類Dev

How do I remove persistent config data from APT?

分類Dev

How to recreate database in SQLAlchemy from Flask?

分類Dev

Flask-SQLAlchemy: How to change table structure?

分類Dev

How to update Boolean Value in Flask SQLAlchemy

分類Dev

In R, how do I drop a column whose values are all FALSE?

分類Dev

Discord.py, how do I delete a role?

分類Dev

How do I set a mock date in Jest?

分類Dev

How do I set up PreAuthenticationAuthenticationProvider?

分類Dev

How do I set up PreAuthenticationAuthenticationProvider?

分類Dev

How do I set an environment variable?

分類Dev

How do I set the ServiceStack ResponseStatus StatusCode?

分類Dev

How do I set an array ? (JAVA classes)

分類Dev

How do I set themes for widgets in windows?

分類Dev

How Do I Correctly Set a getElementById Object?

分類Dev

How do I set "StyleBoxEmpty" on buttons in Godot?

分類Dev

How Do I set a cookie in fetch request?

Related 関連記事

  1. 1

    Flaskの場合-SQLAlchemy:config.pyでcheck_same_thread = Falseを設定するにはどうすればよいですか?

  2. 2

    How do I make SQLAlchemy set values for a foreign key by passing a related entity in the constructor?

  3. 3

    how to set config before import in pytest conftest.py?

  4. 4

    How do I set a value for a hidden field in a Flask form, using wtf.quick_form?

  5. 5

    how do I load image in python flask?

  6. 6

    How do I install the request class in Flask?

  7. 7

    Flask-SQLAlchemy set relationship default value

  8. 8

    How do I check if a set of commands are executed on startup?

  9. 9

    I have a check constraint on my SQL server, how do i set a validation for the Check Constraint in c#?

  10. 10

    Sequelize: How do I use the non-dev config?

  11. 11

    How do I transform this element in my Web.config?

  12. 12

    How do I find the Sitecore Rocks (Hard Rock) Service config?

  13. 13

    how do i load modules and files in the intern config module?

  14. 14

    How do I remove persistent config data from APT?

  15. 15

    How to recreate database in SQLAlchemy from Flask?

  16. 16

    Flask-SQLAlchemy: How to change table structure?

  17. 17

    How to update Boolean Value in Flask SQLAlchemy

  18. 18

    In R, how do I drop a column whose values are all FALSE?

  19. 19

    Discord.py, how do I delete a role?

  20. 20

    How do I set a mock date in Jest?

  21. 21

    How do I set up PreAuthenticationAuthenticationProvider?

  22. 22

    How do I set up PreAuthenticationAuthenticationProvider?

  23. 23

    How do I set an environment variable?

  24. 24

    How do I set the ServiceStack ResponseStatus StatusCode?

  25. 25

    How do I set an array ? (JAVA classes)

  26. 26

    How do I set themes for widgets in windows?

  27. 27

    How Do I Correctly Set a getElementById Object?

  28. 28

    How do I set "StyleBoxEmpty" on buttons in Godot?

  29. 29

    How Do I set a cookie in fetch request?

ホットタグ

アーカイブ