🐛 fix(base.py): handle case where database and tables already exist to prevent error and log a debug message
This commit is contained in:
parent
eb09b0ef59
commit
d6bb6bf3d9
1 changed files with 8 additions and 0 deletions
|
|
@ -3,6 +3,7 @@ import os
|
|||
|
||||
from sqlmodel import SQLModel, Session, create_engine
|
||||
from langflow.utils.logger import logger
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
class Engine:
|
||||
|
|
@ -43,6 +44,13 @@ def create_db_and_tables():
|
|||
logger.debug("Creating database and tables")
|
||||
try:
|
||||
SQLModel.metadata.create_all(Engine.get())
|
||||
except sa.exc.OperationalError as exc:
|
||||
# Check if the error is because the table already exists
|
||||
if "already exists" in str(exc):
|
||||
logger.debug("Database and tables already exist")
|
||||
else:
|
||||
logger.error(f"Error creating database and tables: {exc}")
|
||||
raise RuntimeError("Error creating database and tables") from exc
|
||||
except Exception as exc:
|
||||
logger.error(f"Error creating database and tables: {exc}")
|
||||
raise RuntimeError("Error creating database and tables") from exc
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue