I'm beginner in Ruby on Rails. I dropped my table. But I have the files in the db/migrate
folder. How can I get back my table from those migrate files?
Asked
Active
Viewed 35 times
0

ekremkaraca
- 1,453
- 2
- 18
- 37

karthikaruna
- 3,042
- 7
- 26
- 37
-
thank you for answers.. I used rails generate migration and created a new migration file and copied the change method of the old file into it, then used the rake db:migrate and got my table back.. – karthikaruna Jun 01 '14 at 12:25
3 Answers
1
The ideal way to do this, is using
rake db:setup
This will recreate the database and load the schema into the development database. With every migration rails keeps the current state of the database in schema.rb
(or structure.sql
), and it uses those to efficiently recreate the last state.
If you have pending migrations, you will have to do rake db:migrate
, but this will take more time, since it will redo every step as before.
Also note in some cases it is not possible to run the migrations from the start again, and imho that is not the intention of the migrations.

nathanvda
- 49,707
- 13
- 117
- 139
0
According to this question, you should be able to do the following:
rake db:create #-> creates DB based on the schema file
rake db:migrate #-> populates the db with the various changes in the migrations
If you follow these steps, with nathanvda's
advice, you should be able to solve the issue you're seeing!

Community
- 1
- 1

Richard Peck
- 76,116
- 9
- 93
- 147