etayluz
etayluz

Reputation: 16416

Add column to schema before created_at column

I'm trying to add a column to my table. Here is my migration file:

class AddEmail < ActiveRecord::Migration
  def change
    add_column :apps, :email, :string, after: :website
  end
end

However, when I run it, the newly created email column goes all the way to the last column after updated_at:

ActiveRecord::Schema.define(version: 20141217210326) do

  # These are extensions that must be enabled in order to support this database
  enable_extension "plpgsql"

  create_table "apps", force: true do |t|
    t.string   "name"
    t.string   "iTunes"
    t.string   "website"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.string   "email"
  end

end

What I want is for the new email column to go in between the website and created_at column. How do I do that?

Upvotes: 0

Views: 252

Answers (1)

user3300586
user3300586

Reputation: 11

Postgres doesn't support the ordering of columns in tables. If you don't have any code in production, just alter the original migration that creates the apps table.

Upvotes: 1

Related Questions