knex/knex · error · Error

A name must be specified for the generated seed

Error message

A name must be specified for the generated seed

What it means

Seeder.make(name, config) requires a non-empty name to generate the seed file; if name is falsy (undefined, null, empty string) it throws before touching the filesystem. This is a hard guard at the top of the make method so generated seed files always have a meaningful filename.

Source

Thrown at lib/migrations/seed/Seeder.js:30

// the seeds.
class Seeder {
  constructor(knex) {
    this.knex = knex;
    this.config = this.resolveConfig(knex.client.config.seeds);
  }

  // Runs seed files for the given environment.
  async run(config) {
    this.config = this.resolveConfig(config);
    const files = await this.config.seedSource.getSeeds(this.config);
    return this._runSeeds(files);
  }

  // Creates a new seed file, with a given name.
  async make(name, config) {
    this.config = this.resolveConfig(config);
    if (!name)
      throw new Error('A name must be specified for the generated seed');
    await this._ensureFolder(config);
    const seedPath = await this._writeNewSeed(name);
    return seedPath;
  }

  // Ensures a folder for the seeds exist, dependent on the
  // seed config settings.
  _ensureFolder() {
    const dirs = this.config.seedSource._getConfigDirectories(
      this.config.logger
    );
    const promises = dirs.map(ensureDirectoryExists);
    return Promise.all(promises);
  }

  // Run seed files, in sequence.
  async _runSeeds(seeds) {
    for (const seed of seeds) {

View on GitHub (pinned to e25d54bcb7)

Solutions

  1. Pass a descriptive non-empty name: knex.seed.make('seed-admin-users').
  2. If generating the name dynamically, default it: `await knex.seed.make(name || `seed-${Date.now()}`)`.
  3. Validate the name is a non-empty string before calling make().

Example fix

// before
await knex.seed.make();

// after
await knex.seed.make('admin-users');
Defensive patterns

Strategy: validation

Validate before calling

if (!name || typeof name !== 'string') throw new Error('seed name required');
await knex.seed.make(name);

Type guard

function isSeedName(name) { return typeof name === 'string' && name.trim().length > 0; }

Prevention

When it happens

Trigger: Calling knex.seed.make() with no arguments; passing an empty string or undefined; building the name dynamically from a variable that resolved to undefined.

Common situations: CLI script that forgot the name argument; programmatic seed generation where the name comes from a config that's missing; refactoring that renamed a variable to undefined.

Related errors


AI-assisted analysis of knex/knex@e25d54bcb7 (2026-08-03). Data as JSON: /data/errors/de205aac0c3124ef.json. Report an issue: GitHub.