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

Cannot create self referencing dependency on none primary key #268

Open
efiShtain opened this issue Mar 28, 2024 · 0 comments
Open

Cannot create self referencing dependency on none primary key #268

efiShtain opened this issue Mar 28, 2024 · 0 comments
Assignees

Comments

@efiShtain
Copy link

GORM Playground Link

https://github.com/efiShtain/gorm-playground

Description

I'm trying to create a self referencing table where my foreign key points to a unique index which is not the primary key

I suspect that the migrator tries to create the index after the table creation, but the foreign key constraint is created when the table is created, this order of execution cause the issue

I've tried manually changing CreateIndexAfterCreateTable to false in the migrator, but it broke everything, and since it is hard coded to true, I assume there is a good reason for it

Adding the go struct here

type SelfReferencing struct {
	Name         string `gorm:"uniqueIndex;not null"`
	OriginalName *string
	Original     *SelfReferencing `gorm:"references:Name"`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants