ent / ent/ent

ON CONFLICT DO UPDATE requires inference specification or constraint name

Open
#2,494 4 comments 10 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
17.2k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

- [x] The issue is present in the latest release.
- [x] I have searched the [issues](https://github.com/ent/ent/issues) of this repository and believe that this is not a duplicate.

## Current Behavior 😯

I think this is related to the ID field, it generates with two indexes:
image

one named `pkey` and the other named `id_key`

Code that fails: https://github.com/Southclaws/storyden/blob/main/api/src/resources/category/db.go#L24-L45

Schema: https://github.com/Southclaws/storyden/blob/main/api/src/infra/db/schema/category.go

I followed the docs here for custom ID types: https://entgo.io/docs/schema-fields#id-field and I'm probably going to switch from UUID to something like CUID in future so I want this to work without using the auto increment IDs.

## Expected Behavior 🤔

Updates/upserts to work fine with one single unique ID constraint.

Also, if there are multiple constraints, how would that be done?

## Steps to Reproduce 🕹

Grab the Storyden code above and run the test for `TestCreatePost` which initially seeds the database with users and categories, the seed data for categories is what fails.

## Your Environment 🌎

| Tech | Version |
| ----------- | ------- |
| Go | 1.18 |
| Ent | 0.10.1 |
| Database | Postgres |
| Driver | github.com/jackc/pgx/v4/stdlib |

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.