egg 框架自动创建数据库表结构

 

egg 框架自动创建数据库表结构

 

// {app_root}/app.js
module.exports = app => {
    app.beforeStart(async () => {
        // 从配置中心获取 MySQL 的配置
        // { host: 'mysql.com', port: '3306', user: 'test_user', password: 'test_password', database: 'test' }
        await app.model.sync({ force: true });
    });
};

 

  • force为true 每次都会删除表重建,false会检测代码中创建的model文件在程序执行时创建表

 

相关文章:

  • 2021-12-07
  • 2021-11-23
  • 2021-04-13
  • 2021-11-23
  • 2021-09-19
  • 2021-10-25
  • 2019-11-01
猜你喜欢
  • 2021-09-29
  • 2021-12-04
  • 2021-05-19
  • 2021-11-19
  • 2021-12-15
  • 2021-11-05
  • 2021-12-14
相关资源
相似解决方案