Reputation: 2524
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?
Can I just use string field for the column?
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)
But I got this error:
AttributeError: 'SQLAlchemy' object has no attribute 'JSON'
Upvotes: 2
Views: 1532