question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Migrations queryInterface.addColumn before/after another column?

See original GitHub issue

Anyhow can I use queryInterface.addColumn to add a column before or after another specific column? It’d be nice to have this feature.

Add a column after another column

queryInterface.addColumn('tableA', 'columnC', Sequelize.STRING, {
    after: 'columnB'
});

What do you expect to happen?

The column C should be added after columnB

What is actually happening?

The column append at the end of table

Add a column as the first column in the table

queryInterface.addColumn('tableA', 'columnA', Sequelize.STRING, {
    first: true
});

What do you expect to happen?

The columnA should be added as the first column of the table

What is actually happening?

The column append at the end of table

Dialect: mysql Database version: MySQL 5.6.20 Sequelize version: Sequelize [Node: 6.7.0, CLI: 2.4.0, ORM: 3.24.3, mysql: ^2.11.1]

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:12
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

9reactions
relwellcommented, Mar 16, 2017

This one is currently burning me as well, on Postgres.

8reactions
JefferyHuscommented, Jan 15, 2020

@abdullah2993 postgres doesn’t support adding a column AFTER another one.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Migrations Add Column after specified column and index column
Below is my existing migration file. 'use strict'; module.exports = { up: function (queryInterface, Sequelize) ...
Read more >
“sequelize migration add column after another ... - Code Grepper
module.exports = { up: (queryInterface, Sequelize) => { return queryInterface.sequelize.transaction((t) => { return Promise.all([ queryInterface.
Read more >
How to Add New Fields to Existing Sequelize Migration
Step 1 - Create a new migration ... addColumn( 'Users', // table name 'twitter', // new field name { type: Sequelize.STRING, allowNull: true ......
Read more >
Modifying an existing Sequelize migration | Codementor
addColumn if you want to add a new column or columns. This is a sequelize method queryInterface uses, to add a new column...
Read more >
QueryInterface - Sequelize
Add a new column to a table queryInterface.addColumn('tableA', 'columnC', Sequelize.STRING, { after: 'columnB' // after option is only supported by MySQL }); ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found