尝试两次添加相同模型时的迁移问题

时间:2018-12-03 10:58:42

标签: javascript node.js sql-server sequelize.js sequelize-cli

我正在尝试制作下表:

INTEGER_64

productionStep ItemID | prevId | nextId 是名为ItemId的模型的外键,而itemprevId都是nextId的模型的外键。这些表分别命名为:prductionStepproductionsteps

现在,当我尝试运行以下迁移时:

items

我遇到了问题:

up: (queryInterface, Sequelize) => {
  return queryInterface.addColumn("productionStepOrders", "nextId", {
    type: Sequelize.INTEGER,
    references: {
      model: "productionsteps",
      key: "id"
    },
    onDelete: "SET NULL"
  })
.then(() => {
  return queryInterface.addColumn("productionStepOrders", "itemId", {
    type: Sequelize.INTEGER,
    references: {
      model: "items",
      key: "id"
    },
    onDelete: "SET NULL"
  })
})
.then(()=>{
  return queryInterface.addColumn("productionStepOrders", "prevId", {
    type: Sequelize.INTEGER,
    references: {
      model: "productionsteps",
      key: "id"
    },
    onDelete: "SET NULL"
  })
})
},

down: (queryInterface, Sequelize) => {
  return queryInterface.removeColumn("productionStepOrders", "nextId")
.then(()=>{
  return queryInterface.removeColumn("productionStepOrders", "itemId")
})
.then(()=> {
  return queryInterface.removeColumn("productionStepOrders", "prevId")
})
}

当我使用调试标志运行时:

ERROR: Could not create constraint or index. See previous errors.

它确实创建了ERROR: SequelizeDatabaseError: Could not create constraint or index. See previous errors. at Query.formatError (C:\Users\Jan\Documents\navigatemNode\node_modules\sequelize\lib\dialects\mssql\query.js:315:12) at Request.connection.lib.Request [as userCallback] (C:\Users\Jan\Documents\navigatemNode\node_modules\sequelize\lib\dialects\mssql\query.js:107:25) at Request._this.callback (C:\Users\Jan\Documents\navigatemNode\node_modules\tedious\lib\request.js:60:27) at Connection.endOfMessageMarkerReceived (C:\Users\Jan\Documents\navigatemNode\node_modules\tedious\lib\connection.js:1922:20) at Connection.dispatchEvent (C:\Users\Jan\Documents\navigatemNode\node_modules\tedious\lib\connection.js:1004:38) at Parser.<anonymous> (C:\Users\Jan\Documents\navigatemNode\node_modules\tedious\lib\connection.js:805:18) at emitOne (events.js:116:13) at Parser.emit (events.js:211:7) at Parser.<anonymous> (C:\Users\Jan\Documents\navigatemNode\node_modules\tedious\lib\token\token-stream-parser.js:54:15) at emitOne (events.js:116:13) at Parser.emit (events.js:211:7) at addChunk (C:\Users\Jan\Documents\navigatemNode\node_modules\readable-stream\lib\_stream_readable.js:291:12) at readableAddChunk (C:\Users\Jan\Documents\navigatemNode\node_modules\readable-stream\lib\_stream_readable.js:278:11) at Parser.Readable.push (C:\Users\Jan\Documents\navigatemNode\node_modules\readable-stream\lib\_stream_readable.js:245:10) at Parser.Transform.push (C:\Users\Jan\Documents\navigatemNode\node_modules\readable-stream\lib\_stream_transform.js:148:32) at Parser.afterTransform (C:\Users\Jan\Documents\navigatemNode\node_modules\readable-stream\lib\_stream_transform.js:91:10) at Parser._transform (C:\Users\Jan\Documents\navigatemNode\node_modules\tedious\lib\token\stream-parser.js:69:9) at Parser.Transform._read (C:\Users\Jan\Documents\navigatemNode\node_modules\readable-stream\lib\_stream_transform.js:184:10) at Parser.Transform._write (C:\Users\Jan\Documents\navigatemNode\node_modules\readable-stream\lib\_stream_transform.js:172:83) at doWrite (C:\Users\Jan\Documents\navigatemNode\node_modules\readable-stream\lib\_stream_writable.js:428:64) at writeOrBuffer (C:\Users\Jan\Documents\navigatemNode\node_modules\readable-stream\lib\_stream_writable.js:417:5) at Parser.Writable.write (C:\Users\Jan\Documents\navigatemNode\node_modules\readable-stream\lib\_stream_writable.js:334:11) at Parser.addEndOfMessageMarker (C:\Users\Jan\Documents\navigatemNode\node_modules\tedious\lib\token\token-stream-parser.js:80:26) at Connection.message (C:\Users\Jan\Documents\navigatemNode\node_modules\tedious\lib\connection.js:1913:32) at Connection.dispatchEvent (C:\Users\Jan\Documents\navigatemNode\node_modules\tedious\lib\connection.js:1004:38) at MessageIO.<anonymous> (C:\Users\Jan\Documents\navigatemNode\node_modules\tedious\lib\connection.js:884:18) at emitNone (events.js:106:13) at MessageIO.emit (events.js:208:7) 列和nextId列,但没有创建itemId列,因此在创建prevId列时失败了

当我尝试仅添加一个,所以prevIdprevId时,它都不会出现问题,并且表格与说明相符。

我正在运行MS -SQL Server,具有最新的Sequelize和Sequelize-CLI版本

0 个答案:

没有答案