0

Hello I am about to attempt to run a rails migration on a database of skills that has a :title and :description. I need to remove the description field and I assume it will look something like this:

rails migration remove_column :skills, :description

I am running it by you pros before I attempt it and end up breaking something on accident. Please let me know if I have the right idea about removing the description field from the database. Thanks a lot!

2 Answers 2

0

If skills is the name of your table and description is the name of the column you want to remove, you can type rails g migration RemoveDescriptionFromSkills in your terminal. This will generate a migration file with the name [timestamp]_remove_description_from_skills.rb, located in db/migrate. Edit this file so that it contains the following:

class RemoveDescriptionFromSkills < ActiveRecord::Migration
  def change
    remove_column :skills, :description
  end
end

Then type rake db:migrate in your terminal, and the column will be removed.

For more information, check out this helpful Stack Overflow post: https://stackoverflow.com/a/1992045/3723769.

Note: this answer is intended to describe how to perform the migration. As a safety measure, you should do what Michael Durrant advises before migrating: https://stackoverflow.com/a/25006727/3723769.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks so much! rails makes back end tasks so easy sometimes=D Thanks again Stefan!
0

Here's some of the things that some to mind:-

  • check the existing values to see if there's any data you want
  • see if any indexes exist that should also be dropped.
  • search the application for that field name
  • see if there's an existing rails migration that you can use to DOWN the change

Finally, I would consider creating a change migration as normal, i.e. one that actaully adds the field and then I would run it using the down syntax to remove the field.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.