【发布时间】:2016-04-18 04:49:57
【问题描述】:
我在迁移文件中有以下代码:
import knex from 'knex'
import filterWordsArray from '../seeds/filter_words'
const tables = ['filter_words'];
export async function up(knex) {
await knex.schema.createTable('filter_words', (t) => {
t.uuid('id').primary().defaultTo(knex.raw('uuid_generate_v4()'));
t.string('word');
}).then(function () {
return knex("filter_words").insert(
filterWordsArray
);
})
return Promise.resolve();
};
export async function down(knex) {
for (let table of tables) {
await knex.schema.dropTable(table);
}
return Promise.resolve();
};
包含filterWordsArray的文件有以下内容:
export const filterWordsArray = [
{
word: "something"
},
{
word: "rather"
},
{
word: "filter"
},
{
word: "another"
},
. . .
];
我运行 knex migrate:latest ,没有错误。
$> knex migrate:latest
Using environment: development
Batch 3 run: 1 migrations
.../migrations/23460417191457_add_filter_words.js
$>
但是当我查看数据库时,创建了表但没有插入数据。
所以这是一个 Postgresql 数据库;如果我要手动插入数据,我会去:
mydb=# insert into filter_words(word) values ('something');
mydb=# select * from filter_words;
id | word
--------------------------------------+-----------
2ab8f5d0-ce20-41c2-a0e9-49cbe1b4bd3b | something
(1 row)
请问我在这里错过了什么?
【问题讨论】: