This is an issue related to SQLModel and the open discussion (see below)
When creating a very simple table, the generated SQL code is incorrect. It produces VARCHAR2 and Oracle expects VARCHAR2(length). However, using SQLAlchemy, it works fine if you use for example Column(String(10)). Doing similar in SQLModel does not work and is probably related to the typing, which cast this incorrectly.
FROM DISCUSSION SECTION
First Check
Commit to Help
Example Code
from typing import Optional
from sqlmodel import Field, Session, SQLModel, create_engine
class Hero(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
name: str # This creates the incorrect VARCHAR2 type in Oracle. Setting e.g., String(20) does not help
secret_name: str
age: Optional[int] = None
engine = create_engine("oracle+cx_oracle://<user>:<password>@<dbserver>")
SQLModel.metadata.create_all(engine)
Description
sqlalchemy.exc.DatabaseError: (cx_Oracle:Database:Error) ORA-00906: missing left parenthesis
[SQL:
CREATE TABLE hero(
id INTERGER NOT NULL,
name VARCHAR2 NOT NULL,
secret_name VARCHAR2 NOT NULL,
age INTERGER,
PRIMARY KEY(id)
)
]
Operating System
Windows
Operating System Details
No response
SQLModel Version
0.0.8
Python Version
3.11.4
Additional Context
No response
Originally posted by @angkanas in #641
This is an issue related to
SQLModeland the open discussion (see below)When creating a very simple table, the generated SQL code is incorrect. It produces
VARCHAR2and Oracle expectsVARCHAR2(length). However, usingSQLAlchemy, it works fine if you use for exampleColumn(String(10)). Doing similar in SQLModel does not work and is probably related to the typing, which cast this incorrectly.FROM DISCUSSION SECTION
First Check
Commit to Help
Example Code
Description
sqlalchemy.exc.DatabaseError: (cx_Oracle:Database:Error) ORA-00906: missing left parenthesis
[SQL:
CREATE TABLE hero(
id INTERGER NOT NULL,
name VARCHAR2 NOT NULL,
secret_name VARCHAR2 NOT NULL,
age INTERGER,
PRIMARY KEY(id)
)
]
Operating System
Windows
Operating System Details
No response
SQLModel Version
0.0.8
Python Version
3.11.4
Additional Context
No response
Originally posted by @angkanas in #641