gpt4 book ai didi

javascript - “字段列表”中的未知列 'created_at'

转载 作者:行者123 更新时间:2023-11-29 09:49:54 29 4
gpt4 key购买 nike

这是我的customer_schema.js 文件:

up () {                                                                                                                                        
this.create('customers', (table) => {
table.increments()
table.string('name', 30)
})
}

CustomerSeed.js:

class CustomerSeeder {                                                                                                                           
async run () {
const customer = await Factory
.model('App/Models/Customer')
.create()
console.log('customer: ')
}
}

Customer.js 模型是“空”

我运行迁移,一切正常,但无法运行种子:adonis seeds 抛出此错误消息:

code: 'ER_BAD_FIELD_ERROR',                                                                                                                    
errno: 1054,
sqlMessage: "Unknown column 'created_at' in 'field list'",
sqlState: '42S22',
index: 0,
sql:
"insert into `customers` (`created_at`, `name`, `updated_at`) values ('2019-03-04 20:01:17', 'Peter Walsh', '2019-03-04 20:01:17')" }

为什么会发生这种情况?我什至没有在我的架构文件中声明 table.timestamps() 并且:


describe customers;
+-------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(30) | YES | | NULL | |
+-------+------------------+------+-----+---------+----------------+
2 rows in set (0.01 sec)

最佳答案

编辑:

  static get createdAtColumn () {
return null;
}

static get updatedAtColumn () {
return null;
}

将这两个函数添加到您的模型中,它应该可以工作:)

关于javascript - “字段列表”中的未知列 'created_at',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54989226/

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