-2

Please dont blindly report it as a duplicate question, I have clearly explained I have seen all these solutions, but doesnt make any sense to me as beginner, in the given answers code is there to write, but its not clearly given where to write these code, how to do this....etc This is my Customers table description in the Schema file of my project, now what I need to do is just to remove the index created bellow:

add_index "customers", ["user_id"], name: "index_customers_on_user_id", using: :btree

create_table "customers", force: true do |t|
    t.string   "firstname"
    t.string   "lastname"
    t.string   "email"
    t.string   "phoneno"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.string   "middlename"
    t.string   "salute"
    t.integer  "user_id"
    t.integer  "creater_id"
    t.string   "sale_type"
    t.integer  "referral_id"
  end

  add_index "customers", ["user_id"], name: "index_customers_on_user_id", using: :btree

It may seems like a duplicate question, but in my point of few with all my search in internet lot of methods are given but none worked for me or the methods given doesn't give a correct guide line on where to run the solution code or how to write migration code how to generate migration if required....etc......

As a beginner I found all the solutions complicated to understand, can Anyone please help in doing this in a convenient and easy way ?

Your help is appreciated in advance...!

Praveen George
  • 9,237
  • 4
  • 26
  • 53
  • 4
    Duplicate question to http://stackoverflow.com/questions/21795023/how-to-create-a-migration-to-remove-an-index-only-if-it-exists-rather-than-thro Next time, when asking a question, please provide ways that you have tried it. otherwise it is hard guess which ways have you tried and failed in – Kkulikovskis Oct 16 '15 at 07:47
  • @Kkulikovskis please dont blindly report, mind that I am just a beginner, I have seen lot of answers, but they were not clear to me like where to code, how to do the migration, whether to edit existing migration doc, or to create new one etc...... reporting my trouble as a duplicate can only affect bad abt my reputation rather than helping me out to solve. – Praveen George Oct 16 '15 at 08:12
  • I did not blindly report you, but it is essential that you look around for the answer before posting the question. And the answer, that you have accepted is basically the same as in the link I pasted in. To not affect your reutation badly, check out links provided & delete your question to prevent downgrading – Kkulikovskis Oct 16 '15 at 09:24
  • @Kkulikovskis : In the given link, there is no mention about running the migration command. And also there is no explanation about the editing inside the change function as it only explain about up and down function which I dont have. And last no mentioning about running rake migrate commands. As I am not an expert I am expecting a beginner level explanation to understand things well than an expert can. – Praveen George Oct 16 '15 at 09:34

1 Answers1

1
rails g migration RemoveIndexFromCustomers

Then edit the migration file:

# db/migrate/20151016082936_remove_index_from_customers.rb
class RemoveIndexFromCustomers < ActiveRecord::Migration
  def change
    remove_index :customers, :user_id
  end
end

Note that the timestamp part of the file name will be different.

rake db:migrate
max
  • 96,212
  • 14
  • 104
  • 165