Skip to content

Cannot create self referencing dependency on none primary key #268

Open
@efiShtain

Description

@efiShtain

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"`
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions