What is the best way to drop a table & remove a model in Rails 3?

后端 未结 2 1837
离开以前
离开以前 2020-12-12 16:17

I have a model & a table which I no longer need in my App, I could leave them there but I would like to remove them to keep things tidy.

I\'m trying to figure out

2条回答
  •  [愿得一人]
    2020-12-12 16:51

    The second method is the ideal way to handle this: your migration files are meant to represent how your database has changed over time. The older migration files will remain in your project (in case, hypothetically, you wanted to roll back to an older version), but Rails will not run them when you rake db:migrate because it knows they've already been run (based on data in the database's schema_migrations table).

    Your schema.rb will just be updated once to reflect that your database no longer contains that table.

    One minor tweak to your code: your migration file should drop the table in the up method, and ideally recreate it in the down method. The "up" signifies that your migration drops the table to move forward in time, and if the migration is rolled back, the down method will be run.

提交回复
热议问题