Generate a migration file from schema.rb

后端 未结 2 1107
温柔的废话
温柔的废话 2021-02-01 15:17

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 ma

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-01 15:54

    You could copy and paste schema.rb into a migration and back-date it (e.g. 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.

提交回复
热议问题