Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default values for fields not working as expected with SQLModel in PostgreSQL #1260

Open
1 task done
Yoosuph opened this issue Dec 29, 2024 · 0 comments
Open
1 task done

Comments

@Yoosuph
Copy link

Yoosuph commented Dec 29, 2024

Privileged issue

  • I'm @tiangolo or he asked me directly to create an issue here.

Issue Content

I'm encountering an issue where default values for fields in my SQLModel class are not being applied when using PostgreSQL. Despite specifying default or default_factory for various fields, the database does not seem to handle these defaults, and errors occur during table creation or insertion.

from datetime import datetime
from sqlmodel import Field, SQLModel
from typing import Optional

class Posts(SQLModel, table=True):
id: Optional[int] = Field(default_factory=int, primary_key=True)
title: str
content: str
published: Optional[bool] = Field(default_factory=lambda: True)
created_at: Optional[datetime] = Field(default_factory=datetime.now)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant