我正在使用"knex": "^0.16.5"
和sqlite 3.26
作为数据库。我的迁移工作正常,我的knexfile.js
如下所示:
module.exports = {
development: {
client: 'sqlite3',
connection: {
filename: './db/social_db.sqlite3'
},
},
seeds: {
directory: __dirname + '/seeds'
},
useNullAsDefault: true
};
我的数据库创建正确,但是,我的种子文件不起作用:
我的种子文件如下:
const faker = require("faker")
const createFakeContent = () => ({
title: faker.lorem.sentence,
description: faker.lorem.lines,
image: faker.image.avatar
})
exports.seed = async (knex, Promise) => {
// Inserts seed entries
// Entries
const entries = 100
const fakeContent = []
const table = "scheduled_content"
// Deletes ALL existing entries
await knex(table)
.del()
.then(() => {
for (let i = 0; i < entries; i++) {
fakeContent.push(createFakeContent())
}
})
await knex(table).insert(fakeContent)
}
我收到以下错误:
Error: Error while executing "C:\Users\demo_project\seeds\schedule_content.js" seed: insert into `scheduled_content` (`description`, `image`, `title`) select (select *) as `description`, (select *) as `image`, (select *) as `title` union all select (select *) as `description`, (select *) as `image`, (select *) as `title` - SQLITE_ERROR: no tables specified
at Object.current.then.then.catch.originalError (C:\Users\demo_project\node_modules\knex\lib\seed\Seeder.js:138:21)
Error: SQLITE_ERROR: no tables specified
有人建议我的种子文件做错了吗?
感谢您的答复!