# FactoryBot: FactoryBot::DuplicateDefinitionError: Factory already registered: user

**Code:** `FactoryBot::DuplicateDefinitionError: Factory already registered` · **Category:** Ruby / Rails · **Seen on:** Ruby

Two factory definitions use the same name (or files are loaded twice).

## Meaning

Search for `factory :user` across `spec/factories` and `test/factories`. Duplicates arise from two files, copy/paste, or loading factories twice (`FactoryBot.find_definitions` plus `factory_bot_rails` auto-load). Rename one or merge them; use traits for variations.

## Common causes

- Same factory name defined in two files
- Factories loaded twice (find_definitions + factory_bot_rails)
- Gem engine providing the same factory
- Copy-pasted file
- Lint task loading twice

## Quick fix

1. `grep -rn "factory :user" spec test` and remove the duplicate
2. Don't call `FactoryBot.find_definitions` manually if using factory_bot_rails
3. Use traits instead of duplicate factories

## Detailed fix by platform

### Ruby

1. `grep -rn "factory :user" spec/ test/`

## How to diagnose

1. **Duplicates** — Which files?
2. **Loading** — Twice?
3. **Traits** — Better?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/ruby/factorybot-duplicate-definition)
