DEV Community

Cover image for How to Seed Database using TypeORM Seeding

How to Seed Database using TypeORM Seeding

Francisco Mendes on January 16, 2022

Overview One of the things that, in addition to being immensely convenient during the prototyping of an application, can also be favorab...
Collapse
 
blackkhm profile image
BlackKhm

thanks for sharing

Collapse
 
radandevist profile image
Andrianarisoa Daniel • Edited

Nice post but a long time has passed since this it was written. So I just wrote an up-to-date one on my blog, for thoes who are in need in these times:
How to seed a database with typeorm and faker in 2023

Collapse
 
yesid_lpez_3defc119f8cf0 profile image
Yesid López

The link does not work

Collapse
 
radandevist profile image
Andrianarisoa Daniel

Thank you for notifying, I've just updated it now.

Collapse
 
alexandrecooper profile image
Alexandre Brasil

is not working 😩

Collapse
 
sarajohn130 profile image
sara john
Collapse
 
__horus___ profile image
Babacar Kane

Thanks for sharing😉

Collapse
 
kodunmi profile image
kodunmi

seeds: ["src/db/seeding/seeds//*{.ts,.js}"],
factories: ["src/db/seeding/factories/
/*{.ts,.js}"],

Does not work with nestjs

TypeOrmModule.forRoot({
type: process.env.DB_TYPE as any,
host: process.env.DB_HOSTNAME,
port: Number(process.env.DB_PORT),
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
entities: [Book, Page],
seeds: [InitialDatabaseSeed],
factories: ['src/db/seeding/factories/**/*{.ts,.js}'],
synchronize: true,
logging: process.env.NODE_ENV !== 'production',
}),

Help me

Collapse
 
vicent90 profile image
vicent90

Hi, if you run npm run db:seed two time, is it going to generate 30 users and 200 posts even though you have only one seed?

Collapse
 
thachvearak1991 profile image
thachvearak1991

អរគុណ😻

Collapse
 
billyjov_ profile image
BillyJov

Thanks for sharing.. Is there a way to use this inside an Nx Monorepo ?

Collapse
 
andifaizal profile image
Andi Faizal

Thanks for sharing this articel, really help me a lot.

Collapse
 
asepdadan profile image
Asep Dadan

✖ Could not load the config file!