Skip to content

Conversation

@stonecool
Copy link

Description

Fixes a bug where table field generation returns empty fields array when using multiple database connections with non-default connection.

Problem

When using adm generate with a non-default database connection (e.g. connection = "business"), the generated table model file contains no fields.

The issue is in getFieldsFromConn() function in plugins/admin/modules/tools/generator.go line 444.

Root Cause

// Before (bug):
columnsModel, _ := db.WithDriver(conn).Table(table).ShowColumnsWithComment(conn.GetConfig(connName).Name)`WithDriver(conn)

always sets sql.conn = "default" internally, ignoring the connName parameter. This causes the query to execute on the wrong database connection.

Solution

Use WithDriverAndConnection(connName, conn) instead to respect the specified connection name:

// After (fixed):
columnsModel, _ := db.WithDriverAndConnection(connName, conn).Table(table).ShowColumns()

Testing

Tested with the following configuration:

[database]
driver = mysql
name = goadmin

[database.business]
driver = mysql
name = business

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant