Flask python manage.py db upgrade raise error
<p>I am working on an flask project which contain a large amount of models and some of them make user of <code>from sqlalchemy.dialects.postgresql import JSONB</code>. Form management i created manage.py as per this <a href="http://flask-migrate.readthedocs.io/en/latest/" rel="nofollow">link</a>. <code>pyhton manage.py init &amp; python manage.py migrate</code>
are working fine but when i run <code>pyhton manage.py upgrade</code> the following error occurs in migrated file.</p>

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

<p>Do anyone anyone know how to fix it? Thanks. </p>

<p>You need to import that <code>Text</code></p>

<p>As i searched it comes from <code>sqlalchemy.types</code>, so you need at the top of file import it</p>

<pre><code>from sqlalchemy.types import Text
</code></pre>

<p>But you don't even need to supply <code>astext_type</code> as a parameter, because it defaults to <code>Text()</code>. From <a href="http://docs.sqlalchemy.org/en/latest/dialects/postgresql.html#sqlalchemy.dialects.postgresql.JSON.params.astext_type" rel="nofollow">docs</a> of <code>sqlalchemy.dialects.postgresql.JSON</code>:</p>

<blockquote>
  <p><strong><code>astext_type</code></strong></p>
  
  <p>the type to use for the <code>JSON.Comparator.astext</code> accessor on indexed attributes. Defaults to <code>types.Text</code>.</p>
</blockquote>

<p>And <code>sqlalchemy.dialects.postgresql.JSONB</code> is</p>

<blockquote>
  <p>Bases: <code>sqlalchemy.dialects.postgresql.json.JSON</code></p>
</blockquote>

python postgresql flask flask-sqlalchemy