From 56c8c5ed44c0d6d734c3d3161c642ce8437e2248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ramon=20Br=C3=BClisauer?= Date: Fri, 25 Feb 2022 19:43:27 +0100 Subject: [PATCH] fix: do not emit m2m relations in WithForeignKeys() Fix for https://github.com/uptrace/bun/issues/462 --- query_table_create.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/query_table_create.go b/query_table_create.go index a4ff872fa..a4c35899c 100644 --- a/query_table_create.go +++ b/query_table_create.go @@ -104,6 +104,9 @@ func (q *CreateTableQuery) TableSpace(tablespace string) *CreateTableQuery { func (q *CreateTableQuery) WithForeignKeys() *CreateTableQuery { for _, relation := range q.tableModel.Table().Relations { + if relation.Type == schema.ManyToManyRelation { + continue + } q = q.ForeignKey("(?) REFERENCES ? (?)", Safe(appendColumns(nil, "", relation.BaseFields)), relation.JoinTable.SQLName,