spoqa / sqlalchemy-utc

SQLAlchemy type to store aware datetime values
https://pypi.python.org/pypi/SQLAlchemy-Utc
MIT License
101 stars 20 forks source link

server_default=utcnow for mysql not work #18

Closed ifduyue closed 2 years ago

ifduyue commented 2 years ago

Hello,

from sqlalchemy_utc import UtcDateTime, utcnow

class User(Base):
    joined_at = Column(UtcDateTime, server_default=utcnow())

Generated sql:

mysql> create table users (joined_at datetime default CONVERT_TZ(CURRENT_TIMESTAMP, @@session.time_zone, '+00:00'));
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CONVERT_TZ(CURRENT_TIMESTAMP, @@session.time_zone, '+00:00'))' at line 1
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.29    |
+-----------+
1 row in set (0.00 sec)

Am I doing something wrong?

ifduyue commented 2 years ago

Sorry, I see there is a warning in docstring.

Warning:
    MySQL does not support the use of functions for sqlalchemy
    `server_default=` values. The utcnow function must be used as
    `default=` when interacting with a MySQL server.