like this:

old model:

class TestModel:

    ip = db.Column(db.INET, nullable=False)


new Model:

class TestModel:

    ip = db.Column(db.VARCHAR(), nullable=False, server_default='127.0.0.1')


got migration:

op.alter_column('test', 'ip',
                existing_type=postgresql.INET(),
                type_=sa.VARCHAR(),
                nullable=False)


no default set.


在 2018年9月6日星期四 UTC+8下午9:54:23,Mike Bayer写道:
>
> On Thu, Sep 6, 2018 at 3:50 AM, Yingchen Zhang <cevin....@gmail.com 
> <javascript:>> wrote: 
> > so, alembic not support `default` ( pgsql create columnn ) ? 
>
> it does.  use server_default.    "default" in SQLAlchemy refers to a 
> Python-side default. 
>
>
> > 
> > 在 2018年9月6日星期四 UTC+8上午12:24:54,Mike Bayer写道: 
> >> 
> >> On Wed, Sep 5, 2018 at 11:51 AM, Yingchen Zhang <cevin....@gmail.com> 
> >> wrote: 
> >> > db.Column('text_column', db.VARCHAR(20), default='test_text', 
> >> > server_default='test_text', nullable=True) 
> >> > 
> >> > but, generated code like: 
> >> > 
> >> > sa.Column('text_column', sa.VARCHAR(20), nullable=True), 
> >> 
> >> I assume you are using Alembic autogeneration.   The Python-side 
> >> default "test_text" is not needed in an alembic autogeneration.  The 
> >> server_default however will be rendered. 
> >> 
> >> 
> >> I ran your column as given: 
> >> 
> >> target_metadata = MetaData() 
> >> 
> >> Table( 
> >>     't', target_metadata, 
> >>     Column('text_column', VARCHAR(20), default='test_text', 
> >> server_default='test_text', nullable=True) 
> >> ) 
> >> 
> >> alembic generates: 
> >> 
> >> def upgrade(): 
> >>     # ### commands auto generated by Alembic - please adjust! ### 
> >>     op.create_table('t', 
> >>     sa.Column('text_column', sa.VARCHAR(length=20), 
> >> server_default='test_text', nullable=True) 
> >>     ) 
> >>     # ### end Alembic commands ### 
> >> 
> >> 
> >> 
> >> > 
> >> > 
> >> > how to set column default value ? 
> >> > 
> >> > -- 
> >> > 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 sqlalchemy+...@googlegroups.com. 
> >> > To post to this group, send email to sqlal...@googlegroups.com. 
> >> > 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 sqlalchemy+...@googlegroups.com <javascript:>. 
> > To post to this group, send email to sqlal...@googlegroups.com 
> <javascript:>. 
> > 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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to