【问题标题】:Accidently changed column "type" instead of "name" and now migrations are broken意外更改列“类型”而不是“名称”,现在迁移被破坏
【发布时间】:2014-08-22 18:47:43
【问题描述】:

我想在我的“用户”表中更加具体。我创建了一个名为“location”的迁移,然后意识到我想要的是“state”和“city”。位置迁移很好,但是当我更改名称时,我不小心将类型更改为状态而不是名称。好吧,我想我会运行一个新的迁移并将类型更改回文本,然后重命名该列。那就是我遇到一些错误的地方。我目前在终端得到这个

undefined method `to_sym' for nil:NilClass/usr/local/rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/schema_definitions.rb:216:in `column'

迁移状态

Status   Migration ID    Migration Name
--------------------------------------------------
   up     20140710145422  Devise create users
   up     20140710145425  Add name to users
   up     20140710145432  Add role to users
   up     20140710201635  Create books
   up     20140710204116  Create pits
   up     20140715181941  Add author to books
   up     20140729005134  Fix column name
   up     20140729005452  Add columnto users
   up     20140730031957  Add topic to pit
   up     20140730032046  Add image to pit
   up     20140730032123  Add video to pit
   up     20140730204604  Add summary to pits
   up     20140810150735  Add author to pits
   up     20140810192646  Add about to users
   up     20140811060108  Create comments
   up     20140811184800  Add column to pits
   up     20140819182243  Acts as votable migration
   up     20140822173255  Add location to users
   up     20140822181121  Change user location
  down    20140822181813  Change location field

最后三个迁移文件

class AddLocationToUsers < ActiveRecord::Migration
  def change
    add_column :users, :location, :string
  end
end

class ChangeUserLocation < ActiveRecord::Migration
  def change
    change_column :users, :location, :state
  end
end


class ChangeLocationField < ActiveRecord::Migration
  def change
    change_column :users, :location, :string
  end
end

我尝试了 rake db:rollback,甚至尝试删除并重新创建提供与上述相同错误的数据库。如果这有所作为,我也在使用设计。我基本上什么都做不了,我被困住了。我只想将位置“类型”更改为文本,然后将该列重命名为“城市”。使用 SQlite。希望在这里得到一些帮助。谢谢

【问题讨论】:

  • 向我们展示您的迁移文件
  • 添加了迁移文件

标签: ruby-on-rails migration rake


【解决方案1】:

因此,当我通过 rake db:migrate VERSION=XXXXXXXXXXXX 最终恢复到导致问题的迁移之前的旧迁移时,解决了这个问题。这篇文章的道具在这里

How to delete migration files in Rails 3

【讨论】:

    猜你喜欢
    • 2021-04-26
    • 2021-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-28
    • 1970-01-01
    • 2018-04-20
    相关资源
    最近更新 更多