0

thanks for the help in advance. I have a simple table in Rails 4.0.2 using a development sqlite 3 database. I want to move the order of one of the columns and its not working for some reason. Believe I'm following all the instructions from here that I could find. the migrations run without error, but nothing changes.

My current schema:

create_table "emails", force: true do |t|
  t.string   "email"
  t.boolean  "active"
  t.integer  "member_id"
  t.datetime "created_at"
  t.datetime "updated_at"
  t.integer  "email_type_id"
end

I'm trying to move the 'email_type_id' up to behind 'member_id' with this migration:

class Trynumber5of < ActiveRecord::Migration
  def change
    change_column :emails, :email_type_id, :integer, :after => :member_id
  end
end

I'm sure I'm doing something silly. It runs but nothing happens? I reference this solution for the migration code.

Thanks in advance for any help, its become my white whale of a challenge and driving me crazy;-)

Mark

Community
  • 1
  • 1
MechDog
  • 508
  • 7
  • 18
  • You should read the comments of the solution you posted, it will answer you question. It doesn't seem to work unless you write SQL in your migration it looks like. – CWitty Mar 25 '14 at 19:34
  • I'll take the road less traveled: **Why** are you trying to move it? Using ActiveRecord, you get objects and column order doesn't matter. Using SQL, you can easily get back whatever fields you want in whatever order you want. Do either of those address what you're trying to fix? – colinm Mar 25 '14 at 19:40
  • Re-read it, sounds like it only works against certain database drivers, still surprises me that the schema.rb didn't update its order. – MechDog Mar 25 '14 at 19:46
  • 110% correct, for the active record side there is no issue. Its a convenience request for documentation and low level support if ever needed. – MechDog Mar 25 '14 at 19:48
  • Agree with @colinm, because I tried to do the exact same thing (re-ordering the table columns) when I was starting out with Rails coming from PHP/MySQL. I kept on trying to do what you're doing but at some point I realized that "okay, it probably won't matter for the first x months anyway (it still hasn't mattered)" and "the database will probably change, too". – Daryll Santos Mar 25 '14 at 19:49
  • Fair enough, sounds like its something not really supported by rails. Just thought it would be one of those easy to do things and not a big hassle honestly. Agree that if its a big hassle its not worth a lot of work. – MechDog Mar 25 '14 at 19:53

0 Answers0