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.

Running seed files in particular order

See original GitHub issue

I have a few seed files with inter dependencies. What are the best practices to make seed files run in a specific order, so I don’t get errors about failed foreign key constraints? Should I prefix them with numbers, i.e. 01_, 02_… or is there a better way? Thank you.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
xdevnullcommented, Nov 23, 2018

@orlando what about knex seed:make $(date +%s)_UsersTableSeeder

4reactions
bendruckercommented, Jan 21, 2015

That’s one option. Seeds are sorted by Array.prototype.sort so you can rely on alphabetical order. Your other option is to run seeds that have dependencies in a single file so you have full control over the control flow. Keep in mind that you can always require stuff from another folder (including json) to keep organized.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Running seed files in particular order · Issue #637 · knex/knex
Seeds are sorted by Array.prototype.sort so you can rely on alphabetical order. Your other option is to run seeds that have dependencies in...
Read more >
specify execution order of seed files in rails - Stack Overflow
My approach overrides rake db:seed and runs timestamped seed files under the seed directory in chronological order just like migrations.
Read more >
Rails run seeds in specific order (timestamp your seed files)
Many a times when you generate a model and create a seed file for it, you do so by initializing an empty seed...
Read more >
Database seeding with Knex - DEV Community ‍ ‍
Generally speaking, we should also keep seed files in order, because we may have seed files that rely on previous seeds for their...
Read more >
Database: Seeding - The PHP Framework For Web Artisans
Laravel includes the ability to seed your database with data using seed classes. ... to run other seed classes, allowing you to control...
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