【问题标题】:The find method has not been setup. The PersistedModel has not been correctly attached to a DataSource尚未设置查找方法。 PersistedModel 未正确附加到 DataSource
【发布时间】:2019-02-06 23:33:02
【问题描述】:
Error: Cannot call users.find(). The find method has not been setup. The PersistedModel has not been correctly attached to a DataSource!
    at throwNotAttached (F:\PPL\Laundry\api.lb\node_modules\loopback\lib\persisted-model.js:71:11)
    at Function.find (F:\PPL\Laundry\api.lb\node_modules\loopback\lib\persisted-model.js:259:5)
    at module.exports (F:\PPL\Laundry\api.lb\common\models\users.js:11:11)
    at F:\PPL\Laundry\api.lb\node_modules\loopback-boot\lib\executor.js:251:11
    at Array.forEach (<anonymous>)
    at defineModels (F:\PPL\Laundry\api.lb\node_modules\loopback-boot\lib\executor.js:229:23)
    at setupModels (F:\PPL\Laundry\api.lb\node_modules\loopback-boot\lib\executor.js:197:3)
    at execute (F:\PPL\Laundry\api.lb\node_modules\loopback-boot\lib\executor.js:40:3)
    at bootLoopBackApp (F:\PPL\Laundry\api.lb\node_modules\loopback-boot\index.js:154:3)
    at Object.<anonymous> (F:\PPL\Laundry\api.lb\server\server.js:23:1)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)

【问题讨论】:

    标签: node.js lookback


    【解决方案1】:

    1) 数据源:

    {
      "mysqlDB": {
        "host": "localhost",
        "port": 3306,
        "url": "",
        "database": "databse",
        "password": "",
        "name": "mysqlDB",
        "user": "root",
        "connector": "mysql"
       }
    }
    

    MySQL 默认使用端口 3306

    2)配置模型:model-config.json

    "users": {
        "dataSource": "mysqlDB",
        "public": true
      }
    

    并移除Model中的内部函数

    喜欢:

    'use strict';
    
    module.exports = function(Users) {
    
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-01
      • 2014-03-10
      • 1970-01-01
      • 2014-05-13
      • 1970-01-01
      • 2017-10-29
      相关资源
      最近更新 更多