Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between "rake db:seed" and rake db:fixtures:load"

I am new to Ruby and Rails and am curious about something.

In two different tutorials I am looking at they use different methods for populating a database with basic test information.

One uses "rake db:seed" to pull from a text file with sample data.

The other uses "rake db:fixtures:load".

To me they appear to do the exact same thing.

Do they, or am I missing something here? (Highly likely)

like image 667
jhstephenson Avatar asked Sep 13 '14 01:09

jhstephenson


People also ask

What does rake db seed do?

When you run rake db:seed it will load all the admin data into your application. Rails seeding is generally for development and/or staging environments, there are only a few uses in production. You don't want your production application to seed dummy users!

What is DB seed in rails?

Rails seed files are a useful way of populating a database with the initial data needed for a Rails project. The Rails db/seeds. rb file contains plain Ruby code and can be run with the Rails-default rails db:seed task.

What is the difference between rake and Ruby?

rake is a Make-like program implemented in Ruby. rails is a web framework, which also has some rake tasks. This means that you can have a ruby program with rake but without rails, but not the other way around. By itself, rake will be faster because you don't need to load the whole rails application.

What does db prepare do?

db:prepare: Runs setup if the database does not exist. Otherwise, it runs the migrations. db:reset: Resets your database using your migrations for the current environment. It does this by running the db:drop , db:create , db:migrate tasks.


1 Answers

rake db:seed loads the data from db/seeds.rb into the database. This is generally used for development and production databases. It's permanent data that you use to start an empty application. More information here.

rake db:fixtures:load loads the test fixtures into the test database. This is temporary data used solely by the tests. You can think of fixtures as sample data.

like image 186
Jay Mitchell Avatar answered Oct 22 '22 01:10

Jay Mitchell