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文件在程序執行時創建表

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM