我想把假变量名改成新的,所以我创建了真和新的,但旧的和假的仍然存在!
如何去除假的
irb(main):001:0> item = Item.last Item Load (0.3ms) SELECT "items".* FROM "items" ORDER BY "items"."id" DESC LIMIT ? [["LIMIT", 1]] => #<Item id: 6, title: "Make a cake for your darling", description: "She loves furit ", created_at: "2019-02-27 18:04:15", updated_at: "2019-02-27 18:04:15", user_id: 2, complated_at: nil, completed_at: nil> irb(main):002:0>
我犯了一个错字错误它必须“完成”
我能做什么?
rails g migration remove_complated_at_from_items complated_at:datetime
这一行生成那些代码
class RemoveComplatedAtFromItems < ActiveRecord::Migration[5.2]
def change
remove_column :items, :complated_at, :datetime
end
end
我当前的 schema.rb 文件
ActiveRecord::Schema.define(version: 2019_02_27_204841) do
create_table "items", force: :cascade do |t|
t.string "title"
t.text "description"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
t.datetime "completed_at"
t.datetime "complated_at"
end
现在让我们运行 rails db:migrate
$ rails db:migrate
== 20190227204841 RemoveComplatedAtFromItems: migrating =======================
-- remove_column(:items, :complated_at, :datetime)
-> 0.0038s
== 20190227204841 RemoveComplatedAtFromItems: migrated (0.0039s) ==============
好像一切正常!让我们检查一下schema.rb!
ActiveRecord::Schema.define(version: 2019_02_27_204841) do
create_table "items", force: :cascade do |t|
t.string "title"
t.text "description"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
t.datetime "completed_at"
end
现在一切都很好。最后到左边让我们检查一个对象!
rails c
irb(main):001:0> item = Item.last
Item Load (0.3ms) SELECT "items".* FROM "items" ORDER BY "items"."id" DESC LIMIT ? [["LIMIT", 1]]
=> #<Item id: 6, title: "Make a cake for your darling", description: "She loves furit ", created_at: "2019-02-27 18:04:15", updated_at: "2019-02-27 18:04:15", user_id: 2, completed_at: nil>
完毕!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句