TypeORM Seeding is a utility library designed to simplify the process of populating databases with test or sample data within TypeORM projects. It allows developers to define entity factories, inspired by Laravel's Eloquent factories, and create modular seed scripts for programmatically generating and inserting data. The current stable version is 1.6.2, released in September 2021. The package has a slow release cadence, primarily supporting TypeORM 0.2.x. Key differentiators include a clear separation of factory definitions from seeding logic, support for nested seeding to create related entities, and a command-line interface (CLI) for executing seeders, making it convenient for development, testing, and staging environment setups. It streamlines the creation of complex relational datasets required for application development and testing workflows.
npm install typeorm-seedingVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to define a TypeORM entity, create an associated factory using `typeorm-seeding` and `faker`, implement a `Seeder` class, and then programmatically run the seeder to populate an in-memory SQLite database with sample user data.
Replace calls like `factory(Entity)().seed()` with `factory(Entity)().create()`.
Ensure your project uses TypeORM 0.2.x. If you need to use TypeORM 0.3.x or later, consider alternative seeding solutions or migration paths as `typeorm-seeding` is not actively maintained for newer TypeORM versions.
Review your factory definitions for any deprecated or changed Faker.js API calls and update them according to the Faker.js documentation for the version bundled with `typeorm-seeding` (which implicitly means a relatively old version of Faker.js itself, as the package has not been updated since 2021).
Ensure the package is installed: `npm install typeorm-seeding typeorm faker` or `yarn add typeorm-seeding typeorm faker`. Verify your `tsconfig.json` paths and module resolution if using TypeScript.
Update your factory usage to call `factory(Entity)().create()` instead of `factory(Entity)().seed()`.
Check that the `faker` parameter in your `define` callback is correctly typed and imported. If migrating, review Faker.js documentation for API changes between versions, particularly concerning `faker` (deprecated) vs. `@faker-js/faker` (community maintained fork) and their respective major versions.