[Sqlalchemy-tickets] Issue #3444: sqlalchemy does not emit server_onupdate ON UPDATE clause with My
Brought to you by:
zzzeek
|
From: Charles-Axel D. <iss...@bi...> - 2015-06-09 19:13:43
|
New issue 3444: sqlalchemy does not emit server_onupdate ON UPDATE clause with MySQL https://bitbucket.org/zzzeek/sqlalchemy/issue/3444/sqlalchemy-does-not-emit-server_onupdate Charles-Axel Dein: This seems similar to #3155 and #2631. I have this simple script to reproduce the problem: ``` from sqlalchemy import create_engine from sqlalchemy import func from sqlalchemy.dialects.mysql import DATETIME from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.schema import Column from sqlalchemy.types import Integer, DateTime Base = declarative_base() class Timestamp(Base): __tablename__ = 'timestamps' id = Column(Integer(), primary_key=True) created_at = Column(DateTime(), nullable=False, server_default=func.current_timestamp()) updated_at = Column(DateTime(), nullable=False, server_default=func.current_timestamp(), server_onupdate=func.current_timestamp()) if __name__ == '__main__': engine = create_engine('mysql://root:root@localhost/test', echo=True) Base.metadata.drop_all(engine) Base.metadata.create_all(engine) ``` The SQL that sqlalchemy generates does not have the `ON UPDATE` clause: ``` CREATE TABLE timestamps ( id INTEGER NOT NULL AUTO_INCREMENT, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id) ) ``` A `SHOW CREATE TABLE` query confirms that fact: ``` CREATE TABLE `timestamps` ( `id` int(11) NOT NULL AUTO_INCREMENT, `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 | ``` I'm not 100% sure I'm not causing the problem or have fully understood the two similar tickets. I'll read about it and follow up on this thread if I find something. |