First time on the site, so hi to all and thanks in advance. Longtime lurker and newb.
I\'m working on a web app in flask, using Flask-SqlAlchemy and SqlAlchemy-Searchabl
I ran into this exact issue once, too, when using Flask-Script to add a manage.py
management tool to my application.
The fact that the search_vector
column is empty despite you having added the appropriate TSVectorType
parameters means that the SQLAlchemy-Searchable trigger isn't present in the postgres DB. You can verify its absence by doing a \df+
in psql
command line tool -- you will not see a trigger named article_search_vector_update
. SQLAlchemy-Searchable sets up this trigger to update the content of the search_vector
column when the columns named in TSVectorType(...)
change.
In the case of manage.py
, I had to first call:
db.configure_mappers()
Essentially, you have to configure SQLAlchemy's mappers before calling create_all()
. Without doing this, SQLAlchemy-Searchable will not be given the opportunity to add its search_vector
trigger to populate the TSVectorType
column in the model.The SQLAlchemy-Searchable docs have more on this.
In total, a minimal manage.py
that properly configures SQLAlchemy-Searchable as you require might look like:
#!/usr/bin/env python
from flask.ext.script import Manager
from app import app, db
manager = Manager(app)
@manager.command
def init_db():
"""
Drops and re-creates the SQL schema
"""
db.drop_all()
db.configure_mappers()
db.create_all()
db.session.commit()