Knex-错误:SQLITE_ERROR:未指定表

时间:2019-04-13 20:10:18

标签: node.js sqlite knex.js

我正在使用"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
};

我的数据库创建正确,但是,我的种子文件不起作用:

enter image description here

我的种子文件如下:

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

有人建议我的种子文件做错了吗?

感谢您的答复!

0 个答案:

没有答案