I am using SQLAlchemy (1.2.5), pyodbc(4.0.22). I have created a table using python / SQLAlchemy as follows:
class Persons(Base):
__tablename__ = 'Persons'
ID_Person = Column(Integer(),primary_key = True)
Affiliate_Name = Column(VARCHAR(200), unique=True, nullable = False)
time_created = Column(DateTime(timezone=True), server_default=func.now())
time_updated = Column(DateTime(timezone=True), server_onupdate=func.now())
I can then go into MS SQLServer (2014) and see the table created.
I execute the following commands in SQL Server:
USE [TestDB]
INSERT INTO [dbo].[Persons] (Affiliate_Name) values ('RANDOM NAME')
UPDATE [dbo].[Persons]
SET Affiliate_Name = 'RANDOM NAME2'
WHERE Affiliate_Name = 'RANDOM NAME'
When I look at the data, the time_updated column is still NULL.
EDIT:
I changed my table definition to the following:
class Persons(Base):
__tablename__ = 'Persons'
ID_Person = Column(Integer(),primary_key = True)
Affiliate_Name = Column(VARCHAR(200), unique=True, nullable = False)
time_created = Column(DateTime(timezone=True), server_default=func.now())
time_updated = Column(DateTime(timezone=True), onupdate=datetime.now)
Now, the time_updated column is updated when SQLAlchemy updates data, but will need a trigger to change within MSSQL