---
title: FactoryBot for Seed Data?
teaser:
tags: web,ruby,testing,factory_girl,factory_bot
author: Josh Clayton
published_on: 2013-11-13
---

Occasionally, somebody recommends or asks about using [FactoryBot][factory] to generate
seed data for an application. We recommend against it for a few reasons:

1. **The default attributes of a factory may change over time.** This means
   that, when you're using FactoryBot to generate data in `seeds.rb`, you'll
   need to explicitly assign each attribute in order to ensure that the data is
   correct, defeating the purpose.
1. **Attributes may be added, renamed, or removed.** This means your seeds file
   will always need to be up to date with your factories as well as your
   database schema. You likely won't be running `rake db:seed` every time you
   change a migration. So, your seeds file may become out of sync and it won't
   be immediately obvious. You'll likely notice a breakage when a new developer
   comes onto the project.
1. **Data will still need to be checked for presence before insertion.** The
   ActiveRecord gem gives you this with the "find or create" methods to locate a
   record *or* create it if it can't be found. In addition, those methods will
   basically *force* you to manually define each attribute you want assigned,
   making FactoryBot unnecessary.

[factory]: https://github.com/thoughtbot/factory_bot

## What's next

If you found this useful, you might also enjoy:

- [FactoryBot Callbacks][callbacks]
- [FactoryBot Traits][traits]
- [Use FactoryBot's `build_stubbed` for a Faster Test Suite][build_stubbed]
- [Test-Driven Rails][testing], taught by me

* * *

**Disclaimer:**

Looking for FactoryGirl? The library was renamed in 2017.
[Project name history can be found here.][factory-bot-github-name-change]

[callbacks]: https://thoughtbot.com/blog/get-your-callbacks-on-with-factory-bot-3-3
[traits]: https://thoughtbot.com/blog/remove-duplication-with-factorybots-traits
[build_stubbed]: https://thoughtbot.com/blog/use-factory-bots-build-stubbed-for-a-faster-test
[testing]: https://thoughtbot.com/upcase/test-driven-rails
[factory-bot-github-name-change]: https://github.com/thoughtbot/factory_bot/blob/master/NAME.md
