go-gorm / go-gorm/postgres

Cannot create self referencing dependency on none primary key

Open
#268 0 comments 0 reactions 1 assignee Claimed by @jinzhu View on GitHub
Dominant language
Go
Stars
297
Forks
155
Avg merge
27m
Merged PRs (30d)
2

Description

## 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
```go
type SelfReferencing struct {
Name string `gorm:"uniqueIndex;not null"`
OriginalName *string
Original *SelfReferencing `gorm:"references:Name"`
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.