Fix pydantic_settings import error
- Add pydantic-settings to requirements.txt - Add fallback import for BaseSettings from pydantic if pydantic_settings is not available - Fix ModuleNotFoundError during database migration
This commit is contained in:
parent
e0b4ac8ba6
commit
87c716d3c6
@ -1,6 +1,11 @@
|
||||
from pathlib import Path
|
||||
|
||||
from pydantic_settings import BaseSettings
|
||||
# Try to import BaseSettings from pydantic_settings (for Pydantic v2+)
|
||||
# Fall back to importing from pydantic directly (for Pydantic v1)
|
||||
try:
|
||||
from pydantic_settings import BaseSettings
|
||||
except ImportError:
|
||||
from pydantic import BaseSettings
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
@ -9,14 +14,14 @@ class Settings(BaseSettings):
|
||||
PROJECT_NAME: str = "RESTAPIService"
|
||||
PROJECT_DESCRIPTION: str = "FastAPI REST API Service"
|
||||
VERSION: str = "0.1.0"
|
||||
|
||||
|
||||
# CORS Origins
|
||||
BACKEND_CORS_ORIGINS: list[str] = ["*"]
|
||||
|
||||
|
||||
# Database
|
||||
DB_DIR = Path("/app") / "storage" / "db"
|
||||
DB_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
||||
# SQLite Database URL
|
||||
SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite"
|
||||
|
||||
|
@ -2,6 +2,7 @@ fastapi>=0.100.0
|
||||
uvicorn>=0.23.0
|
||||
sqlalchemy>=2.0.0
|
||||
pydantic>=2.0.0
|
||||
pydantic-settings>=2.0.0
|
||||
alembic>=1.11.0
|
||||
python-dotenv>=1.0.0
|
||||
ruff>=0.0.272
|
||||
|
Loading…
x
Reference in New Issue
Block a user