2

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'

1 Answer 1

2

You need to import JSON or JSONB from sqlalchemy.dialects.postgresql

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.