knex.js - Knex 迁移时间戳没有时间戳
问题描述
exports.up = async function(knex) {
knex.schema.alterTable('posts', (t) => {
t.timestamps(true, true)
})
}
exports.down = async function(knex) {
knex.schema.alterTable('posts', (t) => {
t.dropTimestamps()
})
}
根据文档,这将创建一个created_at
和updated_at
列。
但事实并非如此。
您如何使用 Knex 创建这些列。
解决方案
You are not executing your schema builder. Add await or return your schema builder from migration handler.
exports.up = async function(knex) {
return knex.schema.alterTable('posts', (t) => {
t.timestamps(true, true)
})
}
exports.down = async function(knex) {
return knex.schema.alterTable('posts', (t) => {
t.dropTimestamps()
})
}
Edit after @valem's comment
Code above is pretty much equivalent this, if async / await is not used:
exports.up = function(knex) {
return Promise.resolve(knex.schema.alterTable('posts', (t) => {
t.timestamps(true, true);
}));
}
exports.down = function(knex) {
return Promise.resolve(knex.schema.alterTable('posts', (t) => {
t.dropTimestamps();
}));
}
推荐阅读
- angular - 从输入字段中获取值并传递到路由器链接
- php - 如何使用 http 标头在页面之间传递变量?
- java - 我使用 servlet 和 JDBC 制作了一个用户验证程序,但它不起作用
- android - NoClassDefFoundError 与 Java 8 方法参考
- php - laravel 自定义请求验证 id
- kubernetes - 如何在部署配置中使用相对路径作为秘密 mountPath
- sql - 选择拥有 >1 名西班牙球员的球队
- javascript - 在我使用 tensorflow 的第一步中,模型似乎没有经过培训
- spring-boot - 无法从经理门户将战争文件部署到 Tomcat 服务器
- listview - 当 viewmodel 值发生变化时,如何更新列表视图?