2

I want to update some data using migrations, I have a table with this info:

id userName
1 User1
2 User2
3 User3
4 User4

Following the docs:

https://sequelize.org/master/class/lib/query-interface.js~QueryInterface.html#instance-method-addColumn

I made this:

 const db = require('../src/models');
'use strict';

module.exports = {
  up: (queryInterface, Sequelize) => {
    return Promise.all(
    [
      queryInterface.upsert('Users',{userName:'User1 Updated'},{userName:'User1 Updated'},{userName:'User1'},db.Users,{}),
      queryInterface.upsert('Users',{userName:'User2 Updated'},{userName:'User2 Updated'},{userName:'User2'},db.Users,{}),
      queryInterface.upsert('Users',{userName:'User3 Updated'},{userName:'User3 Updated'},{userName:'User3'},db.Users,{}),
      queryInterface.upsert('Users',{userName:'User4 Updated'},{userName:'User4 Updated'},{userName:'User4'},db.Users,{}),
    ]
    )
  },

  down: (queryInterface, Sequelize) => {
    ...
  }
};

But im getting an error:

ERROR: Incorrect syntax near the keyword 'WHEN'.

R.Romero
  • 161
  • 1
  • 4
  • 15
  • Curious about what the definition of the User model is. I was hitting this as well, and what I was seeing when I added 'console.log()'s into the MSSQL's dialect queryInterface was the "merge search condition" was not being generated for the query. So you'd get an "empty" clause for that, which the MERGE INTO statement needs: https://learn.microsoft.com/en-us/sql/t-sql/statements/merge-transact-sql?view=sql-server-ver15#syntax I believe the reason I was getting an empty "merge search condition" was that the where clause I was supplying was on a field/column that wasn't a PK or unique – lenards Oct 06 '20 at 17:15

0 Answers0