db-migrate / node-db-migrate

Database migration framework for node
Other
2.32k stars 360 forks source link

Adding foreign keys or indexes is broken when cli is executed in Node.js v12.13.1 #668

Closed jhnferraris closed 4 years ago

jhnferraris commented 4 years ago
    facility_id: {
      type: 'int',
      length: 11,
      unsigned: true,
      notNull: false,
      foreignKey: {
        name: 'fk_facility_id',
        table: 'facility',
        rules: {
          onDelete: 'SET NULL',
          onUpdate: 'CASCADE',
        },
        mapping: 'id',
      },
    },

Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[ 'facility_id' ]) REFERENCES facilities ([ 'id' ]) ON DELETE CASCADE ON U' at line 1 at Query.Sequence._packetToError (node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14) at Query.ErrorPacket (node_modules/mysql/lib/protocol/sequences/Query.js:77:18) at Protocol._parsePacket (node_modules/mysql/lib/protocol/Protocol.js:291:23) at Parser._parsePacket (node_modules/mysql/lib/protocol/Parser.js:433:10) at Parser.write (node_modules/mysql/lib/protocol/Parser.js:43:10) at Protocol.write (node_modules/mysql/lib/protocol/Protocol.js:38:16) at Socket. (node_modules/mysql/lib/Connection.js:91:28) at Socket. (node_modules/mysql/lib/Connection.js:525:10) at addChunk (_stream_readable.js:309:12) at readableAddChunk (_stream_readable.js:290:11) at Socket.Readable.push (_stream_readable.js:224:10) at TCP.onStreamRead (internal/stream_base_commons.js:182:23)

  at Protocol._enqueue (node_modules/mysql/lib/protocol/Protocol.js:144:48)
  at Connection.query (node_modules/mysql/lib/Connection.js:201:25)
  at /Users/ferraris-mclinica/Projects/mClinica/SwipeRx/programs-api/node_modules/db-migrate-mysql/index.js:371:29
  at Promise._execute (node_modules/bluebird/js/release/debuggability.js:313:9)
  at Promise._resolveFromExecutor (node_modules/bluebird/js/release/promise.js:488:18)
  at new Promise (node_modules/bluebird/js/release/promise.js:79:10)
  at Object.runSql (node_modules/db-migrate-mysql/index.js:366:12)
  at Object.addForeignKey (node_modules/db-migrate-mysql/index.js:326:17)
  at /Users/ferraris-mclinica/Projects/mClinica/SwipeRx/programs-api/node_modules/db-migrate-base/index.js:154:21
  at Object.recurseCallbackArray (node_modules/db-migrate-base/index.js:130:37)
  at Object.<anonymous> (node_modules/db-migrate-base/index.js:304:23)
  at tryCatcher (node_modules/bluebird/js/release/util.js:16:23)
  at Promise._settlePromiseFromHandler (node_modules/bluebird/js/release/promise.js:517:31)
  at Promise._settlePromise (node_modules/bluebird/js/release/promise.js:574:18)
  at Promise._settlePromise0 (node_modules/bluebird/js/release/promise.js:619:10)
  at Promise._settlePromises (node_modules/bluebird/js/release/promise.js:699:18)
  at _drainQueueStep (node_modules/bluebird/js/release/async.js:138:12)
  at _drainQueue (node_modules/bluebird/js/release/async.js:131:9)
  at Async._drainQueues (node_modules/bluebird/js/release/async.js:147:5)
  at Immediate.Async.drainQueues (node_modules/bluebird/js/release/async.js:17:14)
  at processImmediate (internal/timers.js:439:21)

I tried checking using Node.js v10 and no issue on executing foreign key creation

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

darkocujic commented 4 years ago

I'm having the same issue with Node.js v12.16.1. Not really much to add, error is same as in the opening post.

wzrdtales commented 4 years ago

which driver are you using? This is fixed in the latest mysql driver already (2.1.1)

darkocujic commented 4 years ago

Yeah, you're right. My bad. I had an older version of the driver which is weird since it was installed this morning but installing the db-migrate-mysql@latest version helped. Should've checked the version number... Thanks