I have a python app which is using the SQLmodel library as an ORM wrapper. After successfully creating a database and multiple tables with sqlite3, I like to switch to cockroach db. Therefore I changed the connection string in the create_engine command. I followed the instructions on how to connect to cockroach db here - https://www.cockroachlabs.com/docs/v22.2/connect-to-the-database.html?filters=python&filters=sqlalchemy
My understanding is that SQLmodel fully supports SQLAlchemy connections.
But when I run the create_engine command..
engine = create_engine(os.environ["DB_CONNECTION"], echo=True)
I get the following error:
Exception has occurred: OperationalError
(psycopg2.OperationalError) FATAL: codeParamsRoutingFailed: missing cluster identifier
(Background on this error at: https://sqlalche.me/e/14/e3q8)
psycopg2.OperationalError: FATAL: codeParamsRoutingFailed: missing cluster identifier
The above exception was the direct cause of the following exception:
File "/workspace/app/main.py", line 8, in <module>
SQLModel.metadata.create_all(engine)
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) FATAL: codeParamsRoutingFailed: missing cluster identifier
(Background on this error at: https://sqlalche.me/e/14/e3q8)
The environment variable is set in the VSCode devcontainer.json file
"containerEnv": {
"DB_CONNECTION": "cockroachdb://wg:<removed-password>@cheeky-panther-6202.8nj.cockroachlabs.cloud:26257/wartgeld?sslmode=verify-full"
}
I downloaded the certificate as instructed.
curl --create-dirs -o $HOME/.postgresql/root.crt -O https://cockroachlabs.cloud/clusters/47771648-29f6-4b5d-b684-aeb905732cd7/cert
As for the packages I have installed the required packages according to this instructions - https://github.com/cockroachdb/sqlalchemy-cockroachdb
...
psycopg2-binary 2.9.5
pydantic 1.10.2
PyYAML 6.0
requests 2.28.1
setuptools 65.5.0
SQLAlchemy 1.4.41
sqlalchemy-cockroachdb 1.4.4
sqlalchemy2-stubs 0.0.2a29
sqlmodel 0.0.8
typing_extensions 4.4.0
urllib3 1.26.13
uvicorn 0.20.0
wheel 0.38.4
I am now unsure if the connection string is correct although I copy pasted it directly from the cockroachdb admin interface.