Skip to content
Discussion options

You must be logged in to vote

The following works:

    updated_at: datetime = Field(
        sa_column_kwargs={
            "server_default": func.now(),
            "onupdate": func.now(),
        },
        nullable=False,
    )

Runnable code example in the details:

import time
from datetime import datetime

from sqlmodel import Field, Session, SQLModel, create_engine, func


class SimpleTable(SQLModel, table=True):
    version: int = Field(primary_key=True)
    updated_at: datetime = Field(
        sa_column_kwargs={
            "server_default": func.now(),
            "onupdate": func.now(),
        },
        nullable=False,
    )


def main() -> None:
    engine = create_engine(
        "postgresql://user:myse…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by YuriiMotov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
4 participants