Database Seeding: What & Why
Seeding is the practice of populating a database with an initial or representative set of data -- reference data, sample records, or an admin account -- commonly run when setting up a new environment (local dev, staging, or fresh production).
Seeding vs. Migration
A migration changes the database's schema structure (tables, columns, indexes). Seeding populates that already-defined schema with actual rows of data -- distinct but often complementary steps in setting up an environment.
What Commonly Gets Seeded
Reference data -- static, known-in-advance lists like countries, currency codes, or status values.
A default admin/test account, so whoever sets up a new environment can immediately log in.
Realistic sample data for local development, so a developer doesn't have to manually create records by hand.
Idempotent Seed Scripts
A seed script might get re-run (a fresh database reset, a repeated CI job) -- designing it to check for existing records first (or using an upsert) prevents accumulating duplicate data on each run.
Respecting Dependency Order
If a database enforces foreign key constraints, a seed script inserting a child record referencing a not-yet-existing parent would fail -- seed scripts commonly insert parent records first, then dependent children.
Keep your own version of these notes — editable, searchable, and organised by your stack.
Start free