postgreSQL: SQLModel.metadata.create_all(engine) doesn't create the database file #1523
First Check
Commit to Help
Example Codefrom datetime import datetime
from typing import Optional, Dict
from sqlmodel import Field, SQLModel, create_engine
class SemanticSearch(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
id_user: int
date_time: datetime
query: str
clean_query: str
engine = create_engine('postgresql://postgres:postgres@localhost:5432/embeddings_sts_tf', echo=True)
SQLModel.metadata.create_all(engine)DescriptionFollowing the tutorial user guide based on sqlite I tried to do the same with postgresql database, but contrary to sqlite the Operating SystemLinux Operating System DetailsUbuntu 18.04 LTS SQLModel Version0.0.4 Python Version3.8.8 Additional ContextNo response |
Replies: 2 comments
|
From this stack-overflow post you can't create a postgresql database via from datetime import datetime
from typing import Optional, Dict
from sqlmodel import Field, SQLModel, create_engine, text
class SemanticSearch(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
id_user: int
date_time: datetime
query: str
clean_query: str
engine = create_engine('postgresql://postgres:postgres@localhost:5432/postgres', echo=True)
conn = engine.connect()
conn.execute(text("commit"))
conn.execute(text("create database your_db_name"))
conn.close()
conn.dispose()
engine = create_engine('postgresql://postgres:postgres@localhost:5432/your_db_name', echo=True)
SQLModel.metadata.create_all(engine) |
|
Code examples in docs use SQLite for simplicity. SQLIte creates DB file automatically if not exist. PostgreSQL is more complex thing and it works differently - you need to start the database server (the easiest way is to start the docker container) and create the database manually before running the code. See: |
Code examples in docs use SQLite for simplicity. SQLIte creates DB file automatically if not exist.
PostgreSQL is more complex thing and it works differently - you need to start the database server (the easiest way is to start the docker container) and create the database manually before running the code.
See: