我一直在遵循从头启动KeystoneJS的教程。但是当我进入教程的第二部分,创建数据模型时,出现了这个错误:
Error thrown for request: /keystone/
TypeError: Cannot read property 'id' of undefined
at IndexRoute (/root/websie/node_modules/keystone/admin/server/routes/index.js:39:16)
at Layer.handle [as handle_request] (/root/websie/node_modules/express/lib/router/layer.js:95:5)
at next (/root/websie/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/root/websie/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/root/websie/node_modules/express/lib/router/layer.js:95:5)
at /root/websie/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/root/websie/node_modules/express/lib/router/index.js:335:12)
at next (/root/websie/node_modules/express/lib/router/index.js:275:10)
at /root/websie/node_modules/keystone/admin/server/app/createDynamicRouter.js:26:3
at Layer.handle [as handle_request] (/root/websie/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/root/websie/node_modules/express/lib/router/index.js:317:13)
at /root/websie/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/root/websie/node_modules/express/lib/router/index.js:335:12)
at next (/root/websie/node_modules/express/lib/router/index.js:275:10)
at handleUploadedFiles (/root/websie/node_modules/keystone/lib/uploads.js:6:54)
at Layer.handle [as handle_request] (/root/websie/node_modules/express/lib/router/layer.js:95:5)
GET /keystone/ 500 8.835 ms
由于我是Keystone JS的新手,所以我不太清楚这个问题是代码本身还是数据库造成的。
注意事项:
这些是到目前为止的所有文件:
keystone.js
const keystone = require('keystone')
keystone.init({
'cookie secret': 'SECRET KEY',
'name' : 'theproject',
'user model' : 'User',
'auth' : 'true',
'auto update' : 'true',
});
keystone.import('models');
keystone.start();
User.js:
const keystone = require('keystone');
var User = new keystone.List('User');
User.add({
displayName: { type: String },
password: { type: keystone.Field.Types.Password },
email: { type: keystone.Field.Types.Email, unique: true },
})
User.schema.virtual('canAccessKeystone').get(function () {
return true;
});
User.defaultColumns = 'id, displayName, email';
User.register();
答案 0 :(得分:0)
您的用户模型没有“ id”属性。因此,当您将User.defaultColumns设置为“ id”时,将找不到任何内容。
所有模型都具有“ _id”属性。
我只是从您的默认列中删除“ id”并继续前进。
def exists(str):
try:
eval(str)
return True
except:
return False
exists("lst['sublist']['item']")
如果不能解决问题,则可能是在其他地方请求ID。