我有一些 Knex 迁移脚本,如下所示:
'use strict';
exports.up = function (knex) {
return knex.schema
.hasTable('user')
.then(function (exists) {
if (!exists) {
knex
.schema
.createTable('user', function (table) {
table.increments('id').primary();
table.string('firstName');
table.string('lastName');
table.string('email');
table.string('password');
table.string('username');
})
.then(console.log('created user table'));
}
});
};
Run Code Online (Sandbox Code Playgroud)
我第一次运行这个脚本时,它创建了一个表,这很棒,但后来我注意到该表格式错误(我传递了错误的参数。)所以我从我的数据库中手动删除了创建的表,以及 knex_migrations和 knex_migrations_lock 表,并重新运行迁移命令。现在,它告诉我所有迁移都已运行,但我仍然没有看到该表。是什么赋予了?是否有一段配置隐藏在我需要删除的地方?
添加“返回”。
'use strict';
exports.up = function (knex) {
return knex.schema
.hasTable('user')
.then(function (exists) {
if (!exists) {
return knex // **** udpate
.schema
.createTable('user', function (table) {
table.increments('id').primary();
table.string('firstName');
table.string('lastName');
table.string('email');
table.string('password');
table.string('username');
})
.then(console.log('created user table'));
}
});
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1860 次 |
| 最近记录: |