【问题标题】:Rails migration: Remove column from tableRails 迁移:从表中删除列
【发布时间】:2018-09-22 20:35:54
【问题描述】:

我正在尝试使用 rails 迁移从我的表中删除一些属性,我创建了迁移文件并编写了以下代码:

class RemoveCompanySendReportAttributes < ActiveRecord::Migration[5.1]
  def change
    remove_colmun :companies, :time_limit_for_sending_report, :integer
    remove_column :companies, :automatically_send_report, :boolean
  end
end

它不起作用,这是我终端中的错误:

请使用 register_mime_type 注册一个 mime 类型,然后使用 register_compressorregister_transformerhttps://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md#supporting-all-versions-of-sprockets-in-processors (从块中调用 /home/sa7noun/altagem-project/web/config/initializers/haml.rb:24) == 20180412151847 RemoveCompanySendReportAttributes:迁移 ================ -- remove_colmun(:companies, :time_limit_for_sending_report, :integer) rake 中止! StandardError: 发生错误,这个和以后的一切 迁移已取消:

未定义的方法 `remove_colmun' 用于

【问题讨论】:

  • undefined method remove_colmun - 你在change 方法的第一行有错字

标签: ruby-on-rails database migration


【解决方案1】:

第 1 部分

请使用 register_mime_type 注册 MIME 类型,然后使用 register_compressor 或 register_transformer。

这是一个sprockets 问题,快速修复是

gem 'sprockets', '3.6.3'

但现有的将适用于生产环境。

第 2 部分

remove_column 的迁移错误你写了remove_colmun 这是错误的类型,这就是原因

未定义的方法 `remove_colmun' 用于

它将是remove_column

当你删除一个列时,你不需要提及integerboolean等字段类型......只是简单

remove_column :companies, :time_limit_for_sending_report

在 Gemfile 中进行任何更新后,请确保运行 bundle installupdate

【讨论】:

  • 如果您在迁移的更改方法中使用remove_column,添加类型将使迁移在您需要时可逆。
  • 我再次启动了该命令,没有进行任何修改,这次成功了!我不知道为什么!
  • 我想你把remove_colmun重命名为remove_column,因为右边是remove_column
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多