Skip to content

Commit f538e03

Browse files
Sort columns when create comments (#217)
* Sort columns comments * Simplify m.Migrator.CreateTable columns sortomg
1 parent f437ffe commit f538e03

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

migrator.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ func (m Migrator) CreateTable(values ...interface{}) (err error) {
162162
for _, value := range m.ReorderModels(values, false) {
163163
if err = m.RunWithValue(value, func(stmt *gorm.Statement) error {
164164
if stmt.Schema != nil {
165-
for _, field := range stmt.Schema.FieldsByDBName {
165+
for _, fieldName := range stmt.Schema.DBNames {
166+
field := stmt.Schema.FieldsByDBName[fieldName]
166167
if field.Comment != "" {
167168
if err := m.DB.Exec(
168169
"COMMENT ON COLUMN ?.? IS ?",

0 commit comments

Comments
 (0)