PacktPublishing / Mastering-Flask-Web-Development-Second-Edition

Mastering Flask Web Development, published by Packt
MIT License
153 stars 112 forks source link

Chapter 2 issue - Relationships between models #11

Open AxelRHD opened 2 years ago

AxelRHD commented 2 years ago

I will have exactly the situation to use SQLite in development and a 'real' database in production (first Infobox).

But I can't figure out, where the following code block has to be inserted:

@event.listens_for(Engine, "connect")
def set_sqlite_pragma(dbapi_connection, connection_record):
    cursor = dbapi_connection.cursor()
    cursor.execute("PRAGMA foreign_keys=ON")
    cursor.close()
mtcdultra commented 2 years ago

Hi AxelRHD, I don't know if you already found the solution but for everyone has same problem, I can run the application inserting this code in main.py, below @app.route. Change "@event.listens_for" to "@db.event.listens_for" and include on the top of file "from sqlalchemy.engine import Engine".

Hope that work