Titus Joyson
Titus Joyson

Reputation: 345

Flask python manage.py db upgrade raise error

I am working on an flask project which contains a lot of models and some of them make use of from sqlalchemy.dialects.postgresql import JSONB. From management, I created manage.py as per this link. python manage.py init & python manage.py migrate are working fine but when I run python manage.py upgrade the following error occurs in migrated file.

    sa.Column('images', postgresql.JSONB(astext_type=Text()), nullable=True),
    NameError: global name 'Text' is not defined

Does anyone know how to fix it?

Upvotes: 2

Views: 1963

Answers (2)

Nour Wolf
Nour Wolf

Reputation: 2180

If you are using Alembic, this is fixed in 0.9.0

Upvotes: 0

vishes_shell
vishes_shell

Reputation: 23484

You need to import that Text

As i searched it comes from sqlalchemy.types, so you need at the top of file import it

from sqlalchemy.types import Text

But you don't even need to supply astext_type as a parameter, because it defaults to Text(). From docs of sqlalchemy.dialects.postgresql.JSON:

astext_type

the type to use for the JSON.Comparator.astext accessor on indexed attributes. Defaults to types.Text.

And sqlalchemy.dialects.postgresql.JSONB is

Bases: sqlalchemy.dialects.postgresql.json.JSON

Upvotes: 7

Related Questions