Rails迁移缺失列

时间:2015-03-04 17:35:23

标签: sql ruby-on-rails sqlite ruby-on-rails-4 database-migration

我正在尝试重命名模式中确实存在的列,并且所有信息都在那里,但是当我去更新它时,它会给我一个"缺少的列&#34 ;错误,我无法弄清楚为什么?有什么想法吗?

迁移:

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

错误:

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

1 个答案:

答案 0 :(得分:0)

我已尝试将type列重命名为zip_type。你可以共享表创建迁移吗?另一种解决方案是,您可以删除type列,并将新列添加为zip_type

相关问题