問題
Nodejs 工程下,用 sequelize 向一個現有的 MySQL 數據庫中初始化數據時報錯,如題:
original: Error: Unknown storage engine 'InnoDB'
ENV
- MySQL 5.6
- Sequelize: ^6.25.5
排查
- 查看 mysql 配置 my.ini 中的默認引擎
# The default storage engine that will be used when create new tables when
default-storage-engine=MYISAM
- 查詢 sequelize 文檔,https://sequelize.org/docs/v6/other-topics/dialect-specific-things/#engines---mysqlmariadb-only
The default engine for a model is InnoDB.
修改默認 engine
const sequelize = new Sequelize(db, user, pw, {
define: { engine: 'MYISAM' }
});
- 再次執行,回顯
(node:1940) [SEQUELIZE0006] DeprecationWarning: This database engine version is not supported, please update your database server. More information https://github.com/sequelize/sequelize/blob/main/ENGINE.md
(Use `node --trace-deprecation ...` to show where the warning was created)
數據庫不便升級,考慮 sequelize 是否可降級。實在不行,我只能重裝升級 msqyl 了。
解決方案
- 降級 sequelize 解決
cnpm i sequelize@^5
附
- sequelize 支持 msyql 版本的情況:https://sequelize.org/releases/#mysql-support-table
浙公網安備 33010602011771號