问题
Replicating this link to first test the feasibility of DB migration..
This turns out to be a bug in Alembic, and I tried adding from sqlalchemy.types import Text
to no avail. This link is supposed to be a fix, but I cannot quite see which part of the code I can use for my purpose.
from alembic import autogenerate
from app import db
import sqlalchemy as sa
from sqlalchemy.dialects.postgresql import JSON
from sqlalchemy import Integer, String, TIMESTAMP
from sqlalchemy.types import Text
class Result(db.Model):
__tablename__ = 'results'
id = db.Column(Integer, primary_key = True)
url = db.Column(sa.String())
result_all = db.Column(JSON)
result_no_stop_words = db.Column(JSON)
def __init__(self, url, result_all, result_no_stop_words):
self.url = url
self.result_all = result_all
self.result_no_stop_words = result_no_stop_words
def __repr__(self):
return('<id {}>'.format(self.id))
This, should not return an error. I tried with JSON(astext_type=Text())
and JSON(astext_type=sa.Text())
instead of JSON
too, within db.Column
bracket.
来源:https://stackoverflow.com/questions/54409817/error-alembic-env-name-text-is-not-defined-upon-python-manage-py-db-upgrade