0

I'm trying to rename a column that is definitely there in the schema and all the info is there, but when I go to update it it's giving me a "missing column" error and I can't figure out why? Any ideas?

Migration:

class ChangeColumnName < ActiveRecord::Migration
  def change
    rename_column :postcodes, :type, :zip_type
  end
end

schema.rb

  create_table "postcodes", force: true do |t|
     t.string   "postalcode"
     t.string   "type"
     t.string   "primary_city"
     t.string   "state"
     t.string   "county"
     t.string   "timezone"
     t.string   "area_code"
     t.string   "latitude"
     t.string   "longitude"
     t.string   "estimated_population"
     t.datetime "created_at"
     t.datetime "updated_at"
   end

Error:

DL is deprecated, please use Fiddle
DL is deprecated, please use Fiddle
== 20150304172437 ChangeColumnName: migrating =================================
-- rename_column(:postcodes, :type, :zip_type)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

Missing column postcodes.typeC:/Users/Steve    Q/Documents/GitHub/project1/db/migrate/20150304172437_change_column_name.rb:3:in `change'C:in `migrate' ActiveRecord::ActiveRecordError: Missing column postcodes.type
Steve Q
  • 395
  • 5
  • 28
  • Maybe you renamed this column already. Check columns in your DB. – Maxim Mar 04 '15 at 17:40
  • Try this in rails console `Postcode.last` and past the output here. – Sharvy Ahmed Mar 04 '15 at 18:02
  • So the column is definitely that name. I don't have any records in there yet because "type" is a reserved word in rails which is why I want to change it. Until I change it I can't submit data to create a record...catch 22 – Steve Q Mar 04 '15 at 19:17
  • now I'm getting this error in activeadmin ExecJS::ProgramError in ActiveAdmin::Devise::Sessions#new not sure wha'ts going on there either. – Steve Q Mar 04 '15 at 20:42

1 Answers1

0

I have tried renaming type column to zip_type its working. Another solution is you can delete type column and add new column as zip_type.

cs95
  • 379,657
  • 97
  • 704
  • 746