As you're using Flask-SQLAlchemy you can do with application factory:
from flask_migrate import Migrate
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
migrate = Migrate(compare_type=True)
def create_app(config_name):
app = Flask(__name__)
...
# Migrate
migrate.init_app(app, db)
...
In your requirements:
Flask-SQLAlchemy==2.3.1
flask-migrate==2.1.0
compare_type=True will check for types and names.
On Thu, Jul 26, 2018 at 4:55 AM Simon King <[email protected]> wrote:
> I've never done this, but I see an alternative syntax is:
>
> ALTER TABLE invite_code ALTER COLUMN created_at TYPE TIMESTAMP WITH
> TIME ZONE USING created_at::timestamp
>
> ...so maybe you could use the "postgres_using" flag?
>
>
> http://alembic.zzzcomputing.com/en/latest/ops.html#alembic.operations.Operations.alter_column.params.postgresql_using
>
> Simon
>
> On Thu, Jul 26, 2018 at 11:47 AM Yingchen Zhang <[email protected]>
> wrote:
> >
> > use PostgreSQL change column type need `cast` like `ALTER TABLE
> invite_code ALTER COLUMN created_at::timestamp TYPE TIMESTAMP WITH TIME
> ZONE `,
> > but sqlalchemy auto generated is not use, how specify it.
> >
> > auto generated sql : ALTER TABLE invite_code ALTER COLUMN created_at
> TYPE TIMESTAMP WITH TIME ZONE
> >
> > 在 2018年7月26日星期四 UTC+8下午6:16:10,Simon King写道:
> >>
> >> On Thu, Jul 26, 2018 at 11:03 AM Yingchen Zhang <[email protected]>
> wrote:
> >> >
> >> > old model
> >> >
> >> > class User(db.Model):
> >> > __tablename__ = 'users'
> >> > id = db.Column(db.BigInteger, primary_key=True)
> >> > name = db.Column(db.VARCHAR(50), nullable=False)
> >> >
> >> > email = db.Column(db.VARCHAR(200), nullable=False)
> >> >
> >> > time = db.Column(db.INTGER, nullable=False)
> >> >
> >> >
> >> > new model
> >> >
> >> > class User(db.Model):
> >> > __tablename__ = 'users'
> >> > id = db.Column(db.BigInteger, primary_key=True)
> >> > name = db.Column(db.VARCHAR(50), nullable=False)
> >> >
> >> > email = db.Column(db.VARCHAR(200), nullable=False)
> >> >
> >> > time = db.Column(db.TIMESTAMP(timezone=True), nullable=False)
> >> >
> >> >
> >> > new database table and is still empty, so do not ask why... emmmm
> >> >
> >> > I use flask-sqlalchemy migration tool. When I modified User mode and
> run `python manager.py db migrate`.got :
> >> >
> >> > `INFO [alembic.env] No changes in schema detected.`
> >> >
> >> > So, Sqlalchemy migrate tool only support create and drop ?
> >>
> >> Alembic (the library that flask-sqlalchemy is using for migrations)
> >> supports changing column types. However, it doesn't *auto-detect*
> >> changes of column types by default:
> >>
> >>
> http://alembic.zzzcomputing.com/en/latest/autogenerate.html#what-does-autogenerate-detect-and-what-does-it-not-detect
> >>
> >> """
> >> Autogenerate can optionally detect:
> >>
> >> Change of column type. This will occur if you set the
> >> EnvironmentContext.configure.compare_type parameter to True, or to a
> >> custom callable function. The feature works well in most cases, but is
> >> off by default so that it can be tested on the target schema first. It
> >> can also be customized by passing a callable here; see the section
> >> Comparing Types for details.
> >> """
> >>
> >> Hope that helps,
> >>
> >> Simon
> >
> > --
> > SQLAlchemy -
> > The Python SQL Toolkit and Object Relational Mapper
> >
> > http://www.sqlalchemy.org/
> >
> > To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
> description.
> > ---
> > You received this message because you are subscribed to the Google
> Groups "sqlalchemy" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to [email protected].
> > To post to this group, send email to [email protected].
> > Visit this group at https://groups.google.com/group/sqlalchemy.
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
> description.
> ---
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
>
--
*Andrés Garita*
Desarrollador de Software
andresgarita.com
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.