-
-
Notifications
You must be signed in to change notification settings - Fork 661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flowing large hash values to Postgres BigInt #191
Comments
|
@yinziyan1206 This works if the field is not the primary key. If I want to create a primary key of type BigInteger, I get the exception:
e.g. with |
@unidesigner uhhhh, you can make it a column in sqlalchemy just like this: |
thanks @yinziyan1206 - this did the trick! |
If you want to reference an customer_id: int = Field(None, foreign_key='customer.id', sa_column=Column(BigInteger())) |
This doesn't create foreign key constrant because if sa_column is not undefined it is returned before any parameters are parsed. |
To make it work you should do: |
Just FYI, to get the from typing import Optional
from sqlalchemy import Column, BigInteger
from sqlmodel import Field, SQLModel
class Users(SQLModel, table=True):
id: Optional[int] = Field(default=None, sa_column=Column(BigInteger(), primary_key=True, autoincrement=True))
name: str This generates the following in postgres: CREATE TABLE public."users" (
id bigserial NOT NULL,
name varchar NOT NULL,
PRIMARY KEY (id)
); |
I searched for a long time in the document, but did not find any relevant processing methods. I wonder if the document can introduce the data types of custom data databases for fields and the meaning of uncommon parameters in Field(). This is very helpful for beginners. |
First Check
Commit to Help
Example Code
Description
Using your default Hero example.
Replace the fields with a hash field.
Using postgres, I'm unable to set up the field for big integers. Case A: using standard int results in NumericValueOutOfRange at the psycopg2 level.
So, case B: trying to force a postgres BIGINT, using sqlalchemy BigInteger, I get:
File "pydantic/validators.py", line 715, in find_validators
RuntimeError: no validator found for <class 'sqlalchemy.sql.sqltypes.BigInteger'>, see
arbitrary_types_allowed
in ConfigI know it involves all the different levels, but it seems like a model of use problem (and I had validator problems before that ended up being a change in the way I use sqlmodel.)
Thanks for your creation of sqlmodel - so far I've really enjoyed it along with fastapi!
Operating System
Linux
Operating System Details
No response
SQLModel Version
0.0.4
Python Version
3.8.12
Additional Context
No response
The text was updated successfully, but these errors were encountered: