简体   繁体   中英

Generate a migration file from schema.rb

I'm looking to generate a migration file from the schema.rb. is it possible?

I have many migration files at the moment and would like to combine everything into one master migration file.

I also think i may have accidentally deleted a migration file at some point.

thanks for any help

You could copy and paste schema.rb into a migration and back-date it (eg change the date) so that no existing databases will run it. After you create this migration you can delete all your old migrations.

I disagree with Andrew that you should never delete migrations. Migrations break unexpectedly all the time based on model classes changing and it is very non-trivial to fix them. Since I'm sure you are using version control, you can always look back in the history if you need them for reference.

There's no need to do this. For new installations you should be running rake db:schema:load , not rake db:migrate , this will load the schema into the database, which is faster than running all the migrations.

You should never delete migrations, and certainly not combine them. As for accidentally deleting one, you should be using a version control system , such as Git .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM