Primary key not guaranteed unique?

I configured a column on my resource with primary_key? true and noticed that I can insert multiple records with the same key. Is that intended behavior? I figured for a primary key I should not need to set up a separate identity.
Solution:
primary_key? true on multiple attributes creates a composite primary key
Jump to solution
9 Replies
ZachDaniel
ZachDaniel•2w ago
You need to generate migrations and run them
Songyun
SongyunOP•2w ago
15:10:55.511 [info] Migrations already up
ZachDaniel
ZachDaniel•2w ago
mix ash.codegen add_<field>_to_<resource>_primary_key then mix ash.migrate
Songyun
SongyunOP•2w ago
I'm saying that's already done. This was [part] of the generated migration file
create table(:github_installs, primary_key: false) do
add :installation_id, :bigint, null: false, primary_key: true

add :app_install_id,
references(:installs,
column: :id,
name: "github_installs_app_install_id_fkey",
type: :uuid,
prefix: "public"
),
primary_key: true,
null: false
end
create table(:github_installs, primary_key: false) do
add :installation_id, :bigint, null: false, primary_key: true

add :app_install_id,
references(:installs,
column: :id,
name: "github_installs_app_install_id_fkey",
type: :uuid,
prefix: "public"
),
primary_key: true,
null: false
end
ZachDaniel
ZachDaniel•2w ago
🤔 Oh primary keys are unique together not individually is that what you want?
Solution
ZachDaniel
ZachDaniel•2w ago
primary_key? true on multiple attributes creates a composite primary key
Songyun
SongyunOP•2w ago
Yeah I wanted a composite key and now i'm realizing that the code interface I put together to create the github_install won't stop generating new app_install wrappers 🙃 woops this is on me
Songyun
SongyunOP•2w ago
thanks for taking a look 😅
ZachDaniel
ZachDaniel•2w ago
Ah okay gotcha 😄

Did you find this page helpful?