https://github.com/go-gorm/playground/pull/322

In the existing playground models the user foreign key (manager_id) gets created by the has-many Team relation.

When that is no longer present no foreign key is created for the self-referential has-one relation corresponding to the Manager member.

This is a test case which shows this bug with a separate model:

type Task struct {
    gorm.Model
    Content  string    `gorm:"not null; default:Empty Task" json:"content"`

    ParentTaskID *uint `gorm:"not null" json:"parent_task_id"`
    ParentTask   *Task `gorm:"foreignKey:ParentTaskID" json:"-"`
}

When this is AutoMigrated, parent_task_id isn't marked as a foreign key.

Comment From: ChappIO

I ran into the same issue with PostgreSQL and reported it before I found this ticket. I have closed my report and will keep track of this one.

Comment From: hovinlu

I also met this bug.

Comment From: jinzhu

Should be fixed, thank you for your report.

Comment From: QUDUSKUNLE

This has not been fixed..