-
Notifications
You must be signed in to change notification settings - Fork 93
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
key_name
doesn't work when field is id
#468
Labels
bug
Something isn't working
Comments
if primary_field is None:
if "id" in odm_fields:
if odm_fields["id"].key_name in ("id", None):
raise TypeError(
"can't automatically generate a primary field since an 'id' "
"field already exists"
) But another error
|
It seems that no way to solve it? |
Every document needs to have a UUID, what you are doing is using the name 'id' to store something else, but this is a reserved name for the primary field. You will have to define another field for the primary field: class Project(Model):
uuid: ObjectId = Field(primary_field=True, default_factory=ObjectId)
id: int = Field(key_name='project_id') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug
key_name
doesn't work whenid
Current Behavior
TypeError: can't automatically generate a primary field since an 'id' field already exists
Expected behavior
work as
proid
successfullyEnvironment
python -c "import pydantic.utils; print(pydantic.utils.version_info())
):Additional context
check
key_word
plzThe text was updated successfully, but these errors were encountered: