【发布时间】:2015-05-05 19:59:22
【问题描述】:
我正在尝试重命名架构中肯定存在的列并且所有信息都在那里,但是当我去更新它时它给了我一个“缺少列”错误,我不知道为什么?有什么想法吗?
迁移:
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
【问题讨论】:
-
也许您已经重命名了此列。检查数据库中的列。
-
在 Rails 控制台
Postcode.last中尝试此操作并在此处输入输出。 -
所以列肯定就是那个名字。我还没有任何记录,因为“类型”是 rails 中的保留字,这就是我想更改它的原因。在我更改它之前,我无法提交数据来创建记录...catch 22
-
现在我在 ActiveAdmin::Devise::Sessions#new 中的 activeadmin ExecJS::ProgramError 中遇到此错误,也不确定那里发生了什么。
标签: sql ruby-on-rails sqlite ruby-on-rails-4 database-migration