python - flask-sqlalchemy "no such table" under mod_wsgi -


for reason flask-sqlalchemy seems have problems resolving sqlite tables when running under apache + mod_wsgi.

simplified example:

from models import db, user  app = flask(__name__) app.config['debug'] = true app.config['sqlalchemy_database_uri'] = 'sqlite:////tmp/zop.sqlite3' db.init_app(app) 

models.py:

from flask.ext.sqlalchemy import sqlalchemy db = sqlalchemy()  class user(db.model):     id = db.column(db.integer, primary_key=true)     name = db.column(db.string(50), unique=true)     email = db.column(db.string(120), unique=true)     ... 

basically app works fine when run via python myapp.py

but when run under apache + mod_wsgi, following error when run user.query.filter_by(name=username).first():

operationalerror: (sqlite3.operationalerror) no such table: user [sql: u'select user.id user_id, user.name user_name, user.email user_email \\nfrom user \\nwhere user.name = ?\\n limit ? offset ?'] [parameters: ('foo', 1, 0)] 

is there need change working under apache+mod_wsgi?

ok - figured out. leaving answer here in case else gets bitten this. turns out apache on newer redhat based systems (specifically ones use systemd) uses private /tmp.

this specified in /usr/lib/systemd/system/httpd.service

[service] privatetmp=true 

because of this, db in /tmp/systemd-private-m4xj0e/tmp/zop.sqlite3 rather /tmp/zop.sqlite3. , db in private tmp directory never initialized - running db.create_all() creating /tmp/zop.sqlite3 not /tmp/systemd-private-m4xj0e/tmp/zop.sqlite3. apache throwing errors because couldn't find db.

using alternate non-tmp db location (eg. /var/www/zop.sqlite3) or setting privatetmp=false fixes this

more here: http://blog.oddbit.com/2012/11/05/fedora-private-tmp/


Comments