I have just started learning Ruby On Rails. I am setting up an existing Rails project to my local machine. i hope all the process till yet are ok but i dont get how to import the table data from the existing project also i dont know where the data is stored in Rails? i have a db/development.sqlite3 file i have ran 'rake db:schema:load' and 'rake db:migrate' but i guess these commands have just set up the database structure, but not the data insert. It will be a great if anyone can help me this in easiest way along with telling me few fundamentals
-
Check this post: http://stackoverflow.com/questions/2359205/copying-data-from-one-sqlite-db-to-another – Pavan Apr 09 '14 at 07:26
1 Answers
Your question can be answered in two ways, depending on what data you have already:
Like rake db:migrate
, db:seed
basically takes what's in your db/seeds.rb
& applies to your database. The contents of seeds.db
is just simple ActiveRecord:
Model.create({attr: value, attr: value})
If you have "raw" data you'll like to include, you should open your seeds.rb
file, populate with ActiveRecord commands (like above), and then run rake db:seed
to get it onto the server
DB Porting
If you have data in another stack, you'll have to "port" (I think?) the data. There is no "Rails way" to do this, as everyone's stack / db is different
The process will basically be to create the right tables in both databases with rake db:migrate
, download the relevant data from your old stack, and then upload to your new one

- 76,116
- 9
- 93
- 147