storing serialized data in postgres by SQLAlchemy
<p>I am building an App by using Flask with Postgress and SQLAlchemy. 
There is a table column where I need to store serialized data (JSON). How do I define the field in the model class? </p>

<p>Can I just use string field for the column?</p>

<pre><code>from flask.ext.sqlalchemy import SQLAlchemy
from main import app

db = SQLAlchemy(app)

class Fame (db.Model):
    __tablename__ = "toto"
    id = db.Column('id', db.Integer, primary_key=True)
    data = db.Column('data', db.JSON)
    creation_date = db.Column('creation_date', db.Date, default=datetime.utcnow)
</code></pre>

<p>But I got this error:</p>

<blockquote>
  <p>AttributeError: 'SQLAlchemy' object has no attribute 'JSON'</p>
</blockquote>

<p>You need to import <a href="http://docs.sqlalchemy.org/en/latest/dialects/postgresql.html#sqlalchemy.dialects.postgresql.JSON" rel="nofollow"><code>JSON</code></a> or <a href="http://docs.sqlalchemy.org/en/latest/dialects/postgresql.html#sqlalchemy.dialects.postgresql.JSONB" rel="nofollow"><code>JSONB</code></a> from <code>sqlalchemy.dialects.postgresql</code></p>

python json postgresql sqlalchemy flask-sqlalchemy