I am using "knex": "^0.16.5" and sqlite 3.26 as database. My migration worked fine and my knexfile.js looks like the following:

module.exports = {

  development: {
    client: 'sqlite3',
    connection: {
      filename: './db/social_db.sqlite3'
    },
  },
  seeds: {
    directory: __dirname + '/seeds'
  },
  useNullAsDefault: true
};

My db got correctly created however, my seed file does not work:

enter image description here

My seed file looks like the following:

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)
}

I get the following error:

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

Any suggestion what I am doing wrong with my seed-file?

I appreciate your replies!

0 Answers