开发者

Varchar2 in SQLmodel schema wrong translation

开发者 https://www.devze.com 2022-12-07 18:29 出处:网络
I use an oracle database as a se开发者_Python百科rver into my application. My SQLModel schema looks like below:

I use an oracle database as a se开发者_Python百科rver into my application. My SQLModel schema looks like below:

class HostOutput(SQLModel):
    name: str = Field(index=True)
    region: Optional[str] = None
    os_type: Optional[int] = None
    os_version: Optional[str] = None
    network: Optional[int] = None

Whenever I start my application , sqlalchemy cannot translates the input of a string into VARCHAR2 type in oracle's database. The problem is that VARCHAR2 type requires the amount of bytes for a particular field(column). And the error I get is:

sqlalchemy.exc.DatabaseError: (cx_Oracle.DatabaseError) ORA-00906: missing left parenthesis
[SQL:
CREATE TABLE host (
        name VARCHAR2 NOT NULL,
        region VARCHAR2,
        os_type INTEGER,
        os_version VARCHAR2,
        network INTEGER,
        id INTEGER NOT NULL,
        PRIMARY KEY (id)
)

]
(Background on this error at: https://sqlalche.me/e/14/4xp6)

which essentially tranlates to the database complaining about VARCHAR2 not having parenthesis, for example VARCHAR(5) would be the correct typing.

I tried the following:

from sqlalchemy import String

class HostOutput(SQLModel):
    name: str = Field(index=True)
    region: Optional[String(2)] = None
    os_type: Optional[int] = None
    os_version: Optional[str] = None
    network: Optional[int] = None

but then I get this typing error from python:

TypeError: typing.Optional requires a single type. Got String(length=2).
0

精彩评论

暂无评论...
验证码 换一张
取 消