adonis.js - Adonis factory TypeError:无法读取未定义的属性“名称”
问题描述
这可能已经被问过了,但我找到的答案对我不起作用,所以我希望有人帮助我:)
最近我一直在尝试为我的数据库播种,但我遇到了一个问题..我一直收到这个错误:TypeError: Cannot read property 'name' of undefined
深入挖掘,我发现了错误,但由于我是这个世界的新手,我无法自己修复它..
我的工厂.js
const Factory = use('Factory')
Factory.blueprint('App/Models/User', async faker => {`
return {`
name: faker.first(),
surname: faker.last(),
email: faker.email({ domain: 'somedomain.br' }),
password: 'secret'
}
})
我的 ClientSeeder.js
class ClientSeeder {
async run() {
const role = await Role.findBy('slug', 'client')
console.log(role);
const clients = await Factory.model('App/Models/User').createMany(30)
await Promise.all(clients.map(async client => {
await clients.roles().attach([role.id])
}))
[...]
我得到的错误
TypeError: Cannot read property 'name' of undefined
at Factory.model (/mnt/c/wamp64/www/ecommerce/node_modules/@adonisjs/lucid/src/Factory/index.js:97:39)
at ClientSeeder.run (/mnt/c/wamp64/www/ecommerce/database/seeds/0002_ClientSeeder.js:24:35)
at async SeedDatabase.handle (/mnt/c/wamp64/www/ecommerce/node_modules/@adonisjs/lucid/commands/Seed.js:135:11)
at async /mnt/c/wamp64/www/ecommerce/node_modules/@adonisjs/ace/src/Command/index.js:565:26
这就是我说我挖的部分:node_modules/@adonisjs/lucid/src/Factory/index.js:97:39
就在 97:39
model(name) {
console.log(`Valor saindo: ${name}`);
const blueprint = this.getBlueprint(name)
console.log(`CHEGOU AQUI O BLUEPRINT ${blueprint}`);
return new ModelFactory(blueprint.name, blueprint.callback)
}
//console.log(name) returns 'App/Models/User'
//console.log(blueprint) returns undefined;
现在,在 getBlueprint()
getBlueprint(name) {
console.log(`Nome retornado: ${name}`);
let bp = this._blueprints.find((blueprint) => blueprint.name === name)
console.log(`O BP DESSA PORRA É ${bp}`);
return
}
//console.log(name) returns 'App/Models/User'
//console.log(bp) returns 'undefined'
这里有人知道发生了什么吗?
包版本
"@adonisjs/ace": "^5.0.8",
"@adonisjs/auth": "^3.0.7",
"@adonisjs/bodyparser": "^2.0.5",
"@adonisjs/cors": "^1.0.7",
"@adonisjs/fold": "^4.0.9",
"@adonisjs/framework": "^5.0.9",
"@adonisjs/ignitor": "^2.0.8",
"@adonisjs/lucid": "^6.1.3",
"@adonisjs/mail": "^3.0.10",
"@adonisjs/validator": "^5.0.6",
"@adonisjs/websocket": "^1.0.12",
"adonis-acl": "^1.1.1",
"adonis-bumblebee": "^2.2.0",
"mysql": "^2.18.1"
迁移/Users.js
class UserSchema extends Schema {
up() {
this.create('users', (table) => {
table.increments()
table.string('name', 80).notNullable()
table.string('surname', 80).notNullable()
table.string('email', 254).notNullable().unique()
table.string('password', 60).notNullable()
table.integer('image_id').unique().unsigned()
table.timestamps()
})
}
down() {
this.drop('users')
}
}
Node.js 和 npm 版本
节点:v14.1.0
npm:6.14.7
解决方案
推荐阅读
- pytorch - How to view all possible distributions that can be used in PyTorch kl_divergence function?
- javascript - Implementing BST backed up by Array in Javascript
- node.js - How to pass credit card info via POST
- bash - Extract field using the ‘cut’ command and piping to find the highest value in the extracted field to a separate file
- python - Python using methods from other classes with threads
- 2sxc - 2sxc DnnEnvironment.get_DefaultLanguage()
- angular - 角度测试为什么在单击时需要刷新,但在 triggerEventHandler 中不需要
- reactjs - 如何在 React 应用程序 [typescript] 中从 KeyVault 检索秘密
- c# - C# 在文本文件中搜索字符串并返回不同的字符串
- r - R - 无法从 FTP 服务器下载 gz 文件