server default now() fails

850 views
Skip to first unread message

Victor Varvariuc

unread,
Jun 24, 2013, 8:21:09 AM6/24/13
to sqlalchem...@googlegroups.com
I have this model:

class Counter(Base):

    __tablename__ = 'counter'

    name = Column(String(100), primary_key=True)
    value = Column(Integer)
    created_at = Column(DateTime, nullable=False, server_default=func.now())
    updated_at = Column(DateTime, nullable=False, server_default=func.now(),
                        onupdate=func.now())

Generated Alembic migration is:

def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('counter',
    sa.Column('name', sa.String(length=100), nullable=False),
    sa.Column('value', sa.Integer(), nullable=True),
    sa.Column('created_at', sa.DateTime(), server_default='now()', nullable=False),
    sa.Column('updated_at', sa.DateTime(), server_default='now()', nullable=False),
    sa.PrimaryKeyConstraint('name')
    )
    ### end Alembic commands ###

When applied the source on postgres server is this:

CREATE TABLE counter
(
   name        varchar(100)    NOT NULL,
   value       integer,
   created_at  timestamp       DEFAULT '2013-06-24 16:20:24.923475'::timestamp without time zone NOT NULL,
   updated_at  timestamp       DEFAULT '2013-06-24 16:20:24.923475'::timestamp without time zone NOT NULL
);

Is this a bug or?

Michael Bayer

unread,
Jun 24, 2013, 12:32:30 PM6/24/13
to sqlalchem...@googlegroups.com
change it to:

    Column('created_at', DateTime(), server_default=text('now()'), nullable=False),
    Column('updated_at', DateTime(), server_default=text('now()'), nullable=False),


it's an old issue, #111.   



--
You received this message because you are subscribed to the Google Groups "sqlalchemy-alembic" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy-alem...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages