What is the difference between “rake db:seed” and

2019-03-31 07:28发布

问题:

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)

回答1:

rake db:seeds 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.