question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error on seed:run

See original GitHub issue

Hello all,

First of all thank you very much for the library is definitely a must! I’ve been trying to implement it in a project and I don’t seem to be able to make it work. Im implementing NestJS 7 with Typeorm and Postgres Could you please help me out?

I keep on having this errors:

EntityMetadataNotFound: No metadata for <ENTITY_here> was found.

Error: Could not save entity
    at EntityFactory.<anonymous> (.........../node_modules/typeorm-seeding/src/entity-factory.ts:52:15)

Output of the seed:config without the database configurations

{
  type: 'postgres',
  url: undefined,
  sid: undefined,
  schema: undefined,
  extra: undefined,
  synchronize: false,
  dropSchema: false,
  migrationsRun: false,
  entities: [ 'src/**/*.entity{.ts', '.js}' ],
  migrations: [],
  migrationsTableName: undefined,
  subscribers: [],
  logging: [],
  logger: undefined,
  entityPrefix: undefined,
  maxQueryExecutionTime: undefined,
  debug: undefined,
  cli: {
    entitiesDir: undefined,
    migrationsDir: undefined,
    subscribersDir: undefined
  },
  cache: undefined,
  uuidExtension: undefined,
  factories: [ 'src/**/*.factory{.ts,.js}' ],
  seeds: [ 'src/**/*.seed{.ts,.js}' ]
}

Im trying with a simple entity, factory and seeder

export default class CreateCats implements Seeder {
  public async run(factory: Factory): Promise<void> {
    await factory(Cats)().createMany(5);
  }
}


define(Cats, (faker: typeof Faker) => {
  const cat = new Cats();
  cat.name = "CaT";
  cat.age = 22;

  return cat;
});


@Entity({
  name: "cats",
  orderBy: {
    createdAt: "ASC",
  },
})
export class Cats {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  name: string;

  @Column()
  age: number;
}


What am I missing?

Thank you in advance and I really hope I can use this library because it would save me loads of time

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
DiogoBatistacommented, May 9, 2020

@gerzok for reasons that I still don’t fully understand if I set up an env file with the following key TYPEORM_CONNECTION we see the following connection options.

{
      type: 'postgres',
      url: undefined,
      host: 'host',
      port: '5432',
      username: 'username',
      password: 'password',
      database: 'database_name',
      sid: undefined,
      schema: undefined,
      extra: undefined,
      synchronize: false,
      dropSchema: true,
      migrationsRun: false,
      entities: [],
      migrations: [],
      migrationsTableName: undefined,
      subscribers: [],
      logging: true,
      logger: undefined,
      entityPrefix: undefined,
      maxQueryExecutionTime: undefined,
      debug: undefined,
      cli: {
        entitiesDir: undefined,
        migrationsDir: undefined,
        subscribersDir: undefined
      },
      cache: undefined,
      uuidExtension: undefined
    }

If we omit that specific key we get the configuration we set up in the ormconfig.js

{
      host: 'host',
      username: 'username',
      password: 'password',
      port: '5432',
      logging: [ 'warn', 'error' ],
      synchronize: 'false',
      type: 'postgres',
      database: 'database_name',
      entities: [
        '<absolute path to source>/src/**/*.entity{.ts,.js}'
      ],
      migrations: [
        '<absolute path to source>/src/database/migrations/**/*.ts'
      ],
      seeds: [ 'src/**/*.seed{.ts,.js}' ],
      factories: [ 'src/**/*.factory{.ts,.js}' ],
      logger: 'advanced-console',
      cli: { migrationsDir: 'src/database/migrations' }
    }

It makes sense that it fails because we see that all the necessary information for the typeorm-seeding to work is not set.

why this is is happening is something that I still don’t know if it’s from typeorm configuration options or something specific from typeorm-seeding. My suspicion is that this is the inner works of typeorm changing the output of the configurations. I was able to put it to work in both cli commands and e2e tests that I have on a NestJS project.

I have a ormconfig.js file in the root that fetches the env’s from a .env file like so

const path = require("path"); // eslint-disable-line
module.exports = {
  host: process.env.TYPEORM_HOST,
  username: process.env.TYPEORM_USERNAME,
  password: process.env.TYPEORM_PASSWORD,
  port: process.env.TYPEORM_PORT,
  logging: process.env.TYPEORM_PORT,
  synchronize: process.env.TYPEORM_SYNCHRONIZE,
  type: process.env.TYPEORM_TYPE,
  database: process.env.TYPEORM_DATABASE,
  entities: [path.join(__dirname, "src/**/*.entity{.ts,.js}")],
  migrations: [path.join(__dirname, "src/database/migrations/**/*.ts")],
  seeds: ["src/**/*.seed{.ts,.js}"],
  factories: ["src/**/*.factory{.ts,.js}"],
  logger: "advanced-console",
  logging: ["warn", "error"],
  cli: {
    migrationsDir: path.join("src/database/migrations"),
  },
};

But for the NestJS project I’m actually using the @nestjs/config package to do so and

export default registerAs(
  "database",
  (): TypeOrmModuleOptions => ({
    type: "postgres", 
    host: process.env.TYPEORM_HOST,
    username: process.env.TYPEORM_USERNAME,
    password: process.env.TYPEORM_PASSWORD,
    database: process.env.TYPEORM_DATABASE,
    port: Number(process.env.TYPEORM_PORT),
    entities: [<....entities....>],
    migrationsTableName: "migration",
    migrations: ["src/migration/*.ts"],
    cli: { migrationsDir: "src/migration" },
    synchronize: Boolean(process.env.TYPEORM_SYNCHRONIZE),
    dropSchema: Boolean(process.env.TYPEORM_DROP_SCHEMA),
    logging: Boolean(process.env.TYPEORM_LOGGING),
    // ssl: isProduction() ? Boolean(process.env.SSL) : null
  })
);

@gerzok not sure if this will help you but it took me a while and maybe I can unblock you 😃 and hope that this could make sense for the folks that build this library and they can help us further.

I really like what has been done and I will see if I can dig a bit deeper on why we have different configurations when setting up the env’s.

0reactions
BrothersWarcommented, Aug 3, 2022

I didnt read this thread carefully and spend so much time with this error. @DiogoBatista said right: if u have TYPEORM_CONNECTION or TYPEORM_URL in your .env file then .ormconfig will be ignored. Just delete TYPEORM_CONNECTION and TYPEORM_URL from .env and everything will work fine

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hololive ERROR - speedrun.com
Hololive ERROR (2022). PC. Leaderboards. Full Game Leaderboard · News Guides Resources Streams Forum Statistics Boosters. Latest News.
Read more >
Error code: UUDDLRLRBA - Forum - The Site - speedrun.com
The site is going to be running very slow while elo works on performance improvements. It's been frequently crashing and loading slowly for ......
Read more >
Report a site bug - Forum - The Site - speedrun.com
Is anyone else getting HTTP ERROR 500 after a couple seconds after hitting ... Typicall 500's normally result in a server side failure......
Read more >
Error on run submission - Forum - Pandemic: The Board Game
Is this game accepting submissions? I get an error when I try to submit a new run. Any ideas? ultimatedoom1996 ...
Read more >
Forums / The Site / can't load 1000+ runs - speedrun.com
I think the simplest way they could fix this is just by making leaderboards with over 500 or 1000 just have pages. Pages...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found