sequelize throws ER_CANT_CREATE_TABLE: 无法创建 table 'SequelizeMeta' (errno: 30)

sequelize throws ER_CANT_CREATE_TABLE: Can't create table 'SequelizeMeta' (errno: 30)

由于某种原因,Sequelize 无法创建其元 table:

$ sequelize db:migrate

Sequelize [Node: 6.10.2, CLI: 2.7.0, ORM: 3.30.4]

Loaded configuration file "config\config.json".
Using environment "development".
{ SequelizeDatabaseError: ER_CANT_CREATE_TABLE: Can't create table 'SequelizeMeta' (errno: 30)
    at Query.formatError (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\lib\dialects\mysql\query.js:175:14)
    at Query._callback (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\lib\dialects\mysql\query.js:49:21)
    at Query.Sequence.end (c:\Users\shi\AppData\Roaming\npm\node_modules\mysql\lib\protocol\sequences\Sequence.js:86:24)
    at Query.ErrorPacket (c:\Users\shi\AppData\Roaming\npm\node_modules\mysql\lib\protocol\sequences\Query.js:88:8)
    at Protocol._parsePacket (c:\Users\shi\AppData\Roaming\npm\node_modules\mysql\lib\protocol\Protocol.js:280:23)
    at Parser.write (c:\Users\shi\AppData\Roaming\npm\node_modules\mysql\lib\protocol\Parser.js:75:12)
    at Protocol.write (c:\Users\shi\AppData\Roaming\npm\node_modules\mysql\lib\protocol\Protocol.js:39:16)
    at Socket.<anonymous> (c:\Users\shi\AppData\Roaming\npm\node_modules\mysql\lib\Connection.js:103:28)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at TCP.onread (net.js:551:20)
  name: 'SequelizeDatabaseError',
  message: 'ER_CANT_CREATE_TABLE: Can\'t create table \'SequelizeMeta\' (errno: 30)',
  parent:
   { Error: ER_CANT_CREATE_TABLE: Can't create table 'SequelizeMeta' (errno: 30)
       at Query.Sequence._packetToError (c:\Users\shi\AppData\Roaming\npm\node_modules\mysql\lib\protocol\sequences\Sequence.js:52:14)
       at Query.ErrorPacket (c:\Users\shi\AppData\Roaming\npm\node_modules\mysql\lib\protocol\sequences\Query.js:77:18)
       at Protocol._parsePacket (c:\Users\shi\AppData\Roaming\npm\node_modules\mysql\lib\protocol\Protocol.js:280:23)
       at Parser.write (c:\Users\shi\AppData\Roaming\npm\node_modules\mysql\lib\protocol\Parser.js:75:12)
       at Protocol.write (c:\Users\shi\AppData\Roaming\npm\node_modules\mysql\lib\protocol\Protocol.js:39:16)
       at Socket.<anonymous> (c:\Users\shi\AppData\Roaming\npm\node_modules\mysql\lib\Connection.js:103:28)
       at emitOne (events.js:96:13)
       at Socket.emit (events.js:188:7)
       at readableAddChunk (_stream_readable.js:176:18)
       at Socket.Readable.push (_stream_readable.js:134:10)
       at TCP.onread (net.js:551:20)
       --------------------
       at Protocol._enqueue (c:\Users\shi\AppData\Roaming\npm\node_modules\mysql\lib\protocol\Protocol.js:141:48)
       at Connection.query (c:\Users\shi\AppData\Roaming\npm\node_modules\mysql\lib\Connection.js:208:25)
       at c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\lib\dialects\mysql\query.js:40:21
       at Promise._execute (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\node_modules\bluebird\js\release\debuggability.js:300:9)
       at Promise._resolveFromExecutor (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:483:18)
       at new Promise (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:79:10)
       at Query.run (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\lib\dialects\mysql\query.js:39:17)
       at c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\lib\sequelize.js:849:20
       at c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\node_modules\retry-as-promised\index.js:40:21
       at Promise._execute (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\node_modules\bluebird\js\release\debuggability.js:300:9)
       at Promise._resolveFromExecutor (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:483:18)
       at new Promise (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:79:10)
       at retryAsPromised (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\node_modules\retry-as-promised\index.js:30:10)
       at c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\lib\sequelize.js:848:12
       at tryCatcher (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\node_modules\bluebird\js\release\util.js:16:23)
       at Promise._settlePromiseFromHandler (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:512:31)
       at Promise._settlePromise (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:569:18)
       at Promise._settlePromise0 (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:614:10)
       at Promise._settlePromises (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:693:18)
       at Async._drainQueue (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\node_modules\bluebird\js\release\async.js:133:16)
       at Async._drainQueues (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\node_modules\bluebird\js\release\async.js:143:10)
       at Immediate.Async.drainQueues (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\node_modules\bluebird\js\release\async.js:17:14)
     code: 'ER_CANT_CREATE_TABLE',
     errno: 1005,
     sqlState: 'HY000',
     index: 0,
     sql: 'CREATE TABLE IF NOT EXISTS `SequelizeMeta` (`name` VARCHAR(255) NOT NULL UNIQUE , UNIQUE `SequelizeMeta_name_unique` (`name`), PRIMARY KEY (`name`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_unicode_ci;' },
  original:
   { Error: ER_CANT_CREATE_TABLE: Can't create table 'SequelizeMeta' (errno: 30)
       at Query.Sequence._packetToError (c:\Users\shi\AppData\Roaming\npm\node_modules\mysql\lib\protocol\sequences\Sequence.js:52:14)
       at Query.ErrorPacket (c:\Users\shi\AppData\Roaming\npm\node_modules\mysql\lib\protocol\sequences\Query.js:77:18)
       at Protocol._parsePacket (c:\Users\shi\AppData\Roaming\npm\node_modules\mysql\lib\protocol\Protocol.js:280:23)
       at Parser.write (c:\Users\shi\AppData\Roaming\npm\node_modules\mysql\lib\protocol\Parser.js:75:12)
       at Protocol.write (c:\Users\shi\AppData\Roaming\npm\node_modules\mysql\lib\protocol\Protocol.js:39:16)
       at Socket.<anonymous> (c:\Users\shi\AppData\Roaming\npm\node_modules\mysql\lib\Connection.js:103:28)
       at emitOne (events.js:96:13)
       at Socket.emit (events.js:188:7)
       at readableAddChunk (_stream_readable.js:176:18)
       at Socket.Readable.push (_stream_readable.js:134:10)
       at TCP.onread (net.js:551:20)
       --------------------
       at Protocol._enqueue (c:\Users\shi\AppData\Roaming\npm\node_modules\mysql\lib\protocol\Protocol.js:141:48)
       at Connection.query (c:\Users\shi\AppData\Roaming\npm\node_modules\mysql\lib\Connection.js:208:25)
       at c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\lib\dialects\mysql\query.js:40:21
       at Promise._execute (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\node_modules\bluebird\js\release\debuggability.js:300:9)
       at Promise._resolveFromExecutor (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:483:18)
       at new Promise (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:79:10)
       at Query.run (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\lib\dialects\mysql\query.js:39:17)
       at c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\lib\sequelize.js:849:20
       at c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\node_modules\retry-as-promised\index.js:40:21
       at Promise._execute (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\node_modules\bluebird\js\release\debuggability.js:300:9)
       at Promise._resolveFromExecutor (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:483:18)
       at new Promise (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:79:10)
       at retryAsPromised (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\node_modules\retry-as-promised\index.js:30:10)
       at c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\lib\sequelize.js:848:12
       at tryCatcher (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\node_modules\bluebird\js\release\util.js:16:23)
       at Promise._settlePromiseFromHandler (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:512:31)
       at Promise._settlePromise (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:569:18)
       at Promise._settlePromise0 (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:614:10)
       at Promise._settlePromises (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\node_modules\bluebird\js\release\promise.js:693:18)
       at Async._drainQueue (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\node_modules\bluebird\js\release\async.js:133:16)
       at Async._drainQueues (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\node_modules\bluebird\js\release\async.js:143:10)
       at Immediate.Async.drainQueues (c:\Users\shi\AppData\Roaming\npm\node_modules\sequelize\node_modules\bluebird\js\release\async.js:17:14)
     code: 'ER_CANT_CREATE_TABLE',
     errno: 1005,
     sqlState: 'HY000',
     index: 0,
     sql: 'CREATE TABLE IF NOT EXISTS `SequelizeMeta` (`name` VARCHAR(255) NOT NULL UNIQUE , UNIQUE `SequelizeMeta_name_unique` (`name`), PRIMARY KEY (`name`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_unicode_ci;' },
  sql: 'CREATE TABLE IF NOT EXISTS `SequelizeMeta` (`name` VARCHAR(255) NOT NULL UNIQUE , UNIQUE `SequelizeMeta_name_unique` (`name`), PRIMARY KEY (`name`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_unicode_ci;' }

即使我直接使用SQL命令还是不行:

mysql> CREATE TABLE IF NOT EXISTS `SequelizeMeta` (`name` VARCHAR(255) NOT NULL UNIQUE , UNIQUE `SequelizeMeta_name_unique` (`name`), PRIMARY KEY (`name`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_unicode_ci;
1005 - Can't create table 'SequelizeMeta' (errno: 30)

知道是什么原因造成的吗?

errno: 30 是 linux 代表只读文件系统。显然,这不能通过更改 sequelize 中的任何内容来解决:)

您必须更正文件系统权限,否则同样可能是文件系统已损坏并且 OS 已关闭写入以防止进一步损坏。