gpt4 book ai didi

javascript - 环回错误: Model not found: Book : When I try to run after creating a new model using command

转载 作者:行者123 更新时间:2023-11-28 05:45:58 25 4
gpt4 key购买 nike

当通过生成slc Loopback:model book创建一个新模型时,当我尝试运行 app 时,出现以下错误

> Error: Model not found: Book at Function.registry.getModel> (/home/joseph/node_projects/laplace-master/enquete/node_modules/loopback/lib/registry.js:273:9)> at> /home/joseph/node_projects/laplace-master/enquete/node_modules/loopback-boot/lib/executor.js:156:28> at Array.forEach (native) at defineModels> (/home/joseph/node_projects/laplace-master/enquete/node_modules/loopback-boot/lib/executor.js:151:23)> at setupModels> (/home/joseph/node_projects/laplace-master/enquete/node_modules/loopback-boot/lib/executor.js:140:3)> at execute> (/home/joseph/node_projects/laplace-master/enquete/node_modules/loopback-boot/lib/executor.js:28:3)> at bootLoopBackApp> (/home/joseph/node_projects/laplace-master/enquete/node_modules/loopback-boot/index.js:125:3)> at Object.> (/home/joseph/node_projects/laplace-master/enquete/server/server.coffee:24:1)> at Object.> (/home/joseph/node_projects/laplace-master/enquete/server/server.coffee:1:1)> at Module._compile (module.js:409:26) at Object.loadFile> (/usr/lib/node_modules/coffee-script/lib/coffee-script/register.js:16:19)> at Module.load> (/usr/lib/node_modules/coffee-script/lib/coffee-script/register.js:45:36)> at Function.Module._load (module.js:300:12) at Module.require> (module.js:353:17) at require (internal/module.js:12:17) at Object.> (/home/joseph/node_projects/laplace-master/enquete/handlers/conditionchecker/brand_condition.coffee:5:7)> at Object.> (/home/joseph/node_projects/laplace-master/enquete/handlers/conditionchecker/brand_condition.coffee:1:1)> at Module._compile (module.js:409:26) at Object.loadFile> (/usr/lib/node_modules/coffee-script/lib/coffee-script/register.js:16:19)> at Module.load> (/usr/lib/node_modules/coffee-script/lib/coffee-script/register.js:45:36)> at Function.Module._load (module.js:300:12) at Module.require> (module.js:353:17) at require (internal/module.js:12:17) at Object.> (/home/joseph/node_projects/laplace-master/enquete/common/models/question-group.js:13:3) at Module._compile (module.js:409:26) at Object.Module._extensions..js> (module.js:416:10) at Module.load> (/usr/lib/node_modules/coffee-script/lib/coffee-script/register.js:45:36)> at Function.Module._load (module.js:300:12) at Module.require> (module.js:353:17) at require (internal/module.js:12:17) at> /home/joseph/node_projects/laplace-master/enquete/node_modules/loopback-boot/lib/executor.js:170:20> at Array.forEach (native) at defineModels> (/home/joseph/node_projects/laplace-master/enquete/node_modules/loopback-boot/lib/executor.js:151:23)> at setupModels> (/home/joseph/node_projects/laplace-master/enquete/node_modules/loopback-boot/lib/executor.js:140:3)> at execute> (/home/joseph/node_projects/laplace-master/enquete/node_modules/loopback-boot/lib/executor.js:28:3)> at bootLoopBackApp> (/home/joseph/node_projects/laplace-master/enquete/node_modules/loopback-boot/index.js:125:3)> at Object.> (/home/joseph/node_projects/laplace-master/enquete/server/server.coffee:24:1)> at Object.> (/home/joseph/node_projects/laplace-master/enquete/server/server.coffee:1:1)> at Module._compile (module.js:409:26) at Object.exports.run> (/usr/lib/node_modules/coffee-script/lib/coffee-script/coffee-script.js:154:23)> at compileScript> (/usr/lib/node_modules/coffee-script/lib/coffee-script/command.js:224:29)> at compilePath> (/usr/lib/node_modules/coffee-script/lib/coffee-script/command.js:174:14)> at Object.exports.run> (/usr/lib/node_modules/coffee-script/lib/coffee-script/command.js:98:20)> at Object. (/usr/lib/node_modules/coffee-script/bin/coffee:7:41) at> Module._compile (module.js:409:26) at Object.Module._extensions..js> (module.js:416:10) at Module.load (module.js:343:32) at> Function.Module._load (module.js:300:12) at Function.Module.runMain> (module.js:441:10) at startup (node.js:139:18) at node.js:968:3

Here is my model class and configuration file.

book.js

module.exports = function(Book) {

};

book.json

{
"name": "Book",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"id": {
"type": "string",
"required": true,
"default": "1"
},
"name": {
"type": "string",
"required": true,
"default": "nil"
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}

以及 server/model-config.json

{
"_meta": {
"sources": [
"../common/models",
"./models"
]
},
"User": {
"dataSource": "db"
},
"AccessToken": {
"dataSource": "mysql",
"public": false
},
"ACL": {
"dataSource": "mysql",
"public": false
},
"RoleMapping": {
"dataSource": "mysql",
"public": false
},
"Role": {
"dataSource": "mysql",
"public": false
},
"Book": {
"dataSource": "mysql",
"public": false
}
}

请帮助解决此问题。

最佳答案

我相信您可能尚未初始化数据源中的模型。

您需要在启动脚本中运行以下代码(例如,将代码保存到./server/boot/prepare-db.js。给它您想要的名称,但必须是在 ./server/boot 子文件夹内。)

module.exports = function prepareDB(app, cb) {
var ds = app.dataSources.mysql;
ds.automigrate(function() {
console.log("MySQL db ready");
});
}

automigrate 函数已记录 here .

关于javascript - 环回错误: Model not found: Book : When I try to run after creating a new model using command,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38519094/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com