仲灏小栈 仲灏小栈
首页
大前端
后端&运维
其他技术
生活
关于我
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

仲灏

诚意, 正心, 格物, 致知
首页
大前端
后端&运维
其他技术
生活
关于我
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 《前端项目基础建设》
  • HTML&CSS

  • JavaScript&TypeScript

  • Node

    • nvm 使用
    • nvm 深度使用解析
    • pnpm 学习
    • pnpm 使用及问题处理
    • npm yarn pnpm命令对比
    • koa学习
    • restful api笔记
    • Egg.js 技巧
      • Sequelize
        • sequelize-cli
      • 错误处理
    • Sequelize 学习笔记
    • npm 使用记录
    • node 记错修复
    • npm 仓库
    • 安装npm的过程中发生了什么
    • 想用而找不到的 npm 插件
    • node全局脚本原理解析
    • 转-commander
    • 制作自己的npm包
    • lerna
    • lerna - Lerna an Nx
    • lerna - 功能点
    • lerna API参考
    • Egg.js 技巧 问题集合
    • Node+vue打造全栈资源分享网站
    • 脚手架核心流程开发
    • Untitled
  • 构建

  • Vue

  • React

  • 小程序

  • 跨端

  • Electron

  • WebGL&GIS

  • 浏览器

  • 面经

  • 其他

  • 大前端
  • Node
仲灏
2021-11-29
目录

Egg.js 技巧

# Sequelize

# sequelize-cli

需要  Migrations (opens new window)  来帮我们管理数据结构的变更(在项目的演进过程中,每一个迭代都有可能对数据库数据结构做变更,怎样跟踪每一个迭代的数据变更,并在不同的环境(开发、测试、CI)和迭代切换中,快速变更数据结构呢?) sequelize 提供了  sequelize-cli (opens new window)  工具来实现  Migrations (opens new window)

sequelize <command>

Commands:
  sequelize db:migrate                        Run pending migrations
  sequelize db:migrate:schema:timestamps:add  Update migration table to have timestamps
  sequelize db:migrate:status                 List the status of all migrations
  sequelize db:migrate:undo                   Reverts a migration
  sequelize db:migrate:undo:all               Revert all migrations ran
  sequelize db:seed                           Run specified seeder
  sequelize db:seed:undo                      Deletes data from the database
  sequelize db:seed:all                       Run every seeder
  sequelize db:seed:undo:all                  Deletes data from the database
  sequelize db:create                         Create database specified by configuration
  sequelize db:drop                           Drop database specified by configuration
  sequelize init                              Initializes project
  sequelize init:config                       Initializes configuration
  sequelize init:migrations                   Initializes migrations
  sequelize init:models                       Initializes models
  sequelize init:seeders                      Initializes seeders
  sequelize migration:generate                Generates a new migration file      [aliases: migration:create]
  sequelize model:generate                    Generates a model and its migration [aliases: model:create]
  sequelize seed:generate                     Generates a new seed file           [aliases: seed:create]

Options:
  --version  Show version number                                                  [boolean]
  --help     Show help                                                            [boolean]

Please specify a command
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 升级数据库
npx sequelize db:migrate
# 如果有问题需要回滚,可以通过 `db:migrate:undo` 回退一个变更
# npx sequelize db:migrate:undo
# 可以通过 `db:migrate:undo:all` 回退到初始状态
# npx sequelize db:migrate:undo:all
1
2
3
4
5
6

# 错误处理

  • 2020-10-23 15:20:10,104 ERROR 124768 [-/127.0.0.1/-/8ms POST /api/v1/video] nodejs.SequelizeDatabaseError: Incorrect string value: '\xE5\x8F\x8D\xE5\xAF\xB9...' for column 'introduce' at row 1

    _    at Query.formatError (D:\Code\Work\wxwl-resource-share\node_modules_sequelize@6.3.5@sequelize\lib\dialects\mysql\query.js:239:16)_ _    at Query.run (D:\Code\Work\wxwl-resource-share\node_modules_sequelize@6.3.5@sequelize\lib\dialects\mysql\query.js:54:18)_ _    at processTicksAndRejections (internal/process/task_queues.js:97:5)_ name: "SequelizeDatabaseError" parent: {"code":"ER_TRUNCATED_WRONG_VALUE_FOR_FIELD","errno":1366,"sqlState":"HY000","sqlMessage":"Incorrect string value: '\xE5\x8F\x8D\xE5\xAF\xB9...' for column 'introduce' at row 1","sql":"INSERT INTO videos (id,category_id,title,introduce,detail,create_date) VALUES (DEFAULT,?,?,?,?,?);","parameters":[1,"test11","tess 反对 t","231231","2020-10-23 07:20:10"]} original: {"code":"ER_TRUNCATED_WRONG_VALUE_FOR_FIELD","errno":1366,"sqlState":"HY000","sqlMessage":"Incorrect string value: '\xE5\x8F\x8D\xE5\xAF\xB9...' for column 'introduce' at row 1","sql":"INSERT INTO videos (id,category_id,title,introduce,detail,create_date) VALUES (DEFAULT,?,?,?,?,?);","parameters":[1,"test11","tess 反对 t","231231","2020-10-23 07:20:10"]} sql: "INSERT INTO videos (id,category_id,title,introduce,detail,create_date) VALUES (DEFAULT,?,?,?,?,?);" parameters: [1,"test11","tess 反对 t","231231","2020-10-23 07:20:10"] pid: 124768 hostname: DESKTOP-FUCU627

上次更新: 2022/06/05, 20:31:36
restful api笔记
Sequelize 学习笔记

← restful api笔记 Sequelize 学习笔记→

最近更新
01
vim日常使用记录
04-02
02
滑动窗口最大值
04-02
03
有效的字母异位词
04-02
更多文章>
Theme by Vdoing | Copyright © 2021-2025 izhaong | github | 蜀ICP备2021031194号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式