Faker - populate fake data for your database.

Edward Arias
3 min readAug 1, 2021

Are you working on a project and you need random data to fill up/populate your back-end database? Look no further!

“Faker” is a library that generates fake data such as names, addresses, countries, book’s name, game’s name and many more. The only downside is that the data generated won’t be unique by default. However, you can overcome this by including “.unique” in order to populate unique names.

-example-

Faker::Name.name

Faker::Name.unique.name

-Installation-

Type the below in your terminal

gem install faker

In your “Gemfile” if not there already, add — gem ‘faker’ as seen in the image below.

If your data isn’t populating you can add a “require” to your seed or config file.

After installation, go to your seed file and start adding data to populate in the database(screenshot below). As you can see, I am creating 15 fake names and email addresses by assigning the fakers to a variable of name and email and then assigning those variables to the attributes in my table.

Once you finish adding all your fake data save the file and open your preferred database. I will use SQLite since I already had it installed. You can do -view-command palette- or shift+command+P and select SQLite: Open Database. (screenshots below). Please note that your tables would have to be migrated and seeded in order to see the data in the database.

Once clicked, you will be able to see a “SQLITE EXPLORER” section(screenshotbelow). Hover over the table you would like to see and click on the “play” button next to it to open that particular table.

As you can see, this will open a SQL table where you can see the fake data you added in your seed file . Here you can see that -

“Faker::funnyName.two_word_name” populated “Doug Graves”

“Faker::Internet.email” populated “cyrstal@isozk.io”

In the image below I use “Faker::Address.full.address” and populated a random addresses.

You can image what the two below will populate.

“Fakker::Artist.name” populated random artist’ name

“Fakker::Nation.flag” populated random flags

You can navigate to their site -https://github.com/faker-ruby/faker to learn more. Below are some of the many “Faker” you can use. Go and have fun populating some fakers!

--

--