Rename Column query output

I’m trying to rename a column in a migration file using table.renameColumn('user_id', 'account_id') for some reason the query output when running adonis migration:run --log is this:

Queries for 1559227379377_picture_update_schema.js
  show fields from `pictures` where field = 'user_id'

I’m pretty sure that is not the right query. Does lucid supports that method?

1 Like

Is user_id a foreign key ?

Yes. Should I drop this constraint in one migration and then execute the rename in another one?

In that case, yes, you should remove the constraint first.
Hope you know how to use the run() and down() methods of the migration files.

I hope so too :grin: I will test this out in a test db first.

Output query is still the same even after dropping constraint.

.table('pictures', (table) => {
        // alter table
        table.dropForeign('user_id')
 })

it ran successfully

migrate: 1559227379377_picture_update_schema.js
Database migrated successfully in 4.04 s

next migration was this

this.table('pictures', (table) => {
      // alter table
      table.renameColumn('user_id', 'account_id')
    })

which yields the same output as before

Queries for 1559233202455_rename_picture_user_id_schema.js
  show fields from `pictures` where field = 'user_id'