Skip to content
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

sqlite: primary key contstraint gets lost when embedded struct also contains primary key #6945

Open
phil9909 opened this issue Apr 8, 2024 · 2 comments
Assignees
Labels
type:with reproduction steps with reproduction steps

Comments

@phil9909
Copy link

phil9909 commented Apr 8, 2024

GORM Playground Link

go-gorm/playground#712

Description

For the following model

type Common struct {
	TenantID uint `gorm:"primarykey"`
}

type User struct {
	Common
	UserID string `gorm:"primarykey"`
	// ...
}

this SQL DDL is generated

CREATE TABLE `users` (`tenant_id` integer PRIMARY KEY AUTOINCREMENT,`user_id` text, [...])

Notice: The user_id is missing the PRIMARY KEY constraint

It worked fine with gorm.io/driver/sqlite v1.5.3 but is broken in gorm.io/driver/sqlite v1.5.4

@github-actions github-actions bot added the type:with reproduction steps with reproduction steps label Apr 8, 2024
@gg1229505432
Copy link

Generally, An SQL statement can have only one primary key

@phil9909
Copy link
Author

Hi @gg1229505432, thank you for your replay.

Generally, An SQL statement can have only one primary key

Yes, a SQL relation (I guess this is what you meant with statement, because a statement does not have a primary key, it might specify one, if it's a DDL statement) can only have one primary key, hence the name primary key.

But that is completely unrelated to this issue. I don't want multiple primary keys, that would be insane 😅

What I want is a composite primary key, which as per documentation gorm supports: https://gorm.io/docs/composite_primary_key.html and as I said already: It was even working in older versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:with reproduction steps with reproduction steps
Projects
None yet
Development

No branches or pull requests

3 participants