【问题标题】:Syntax error fixing devise to not use email语法错误修复设计不使用电子邮件
【发布时间】:2014-04-07 01:14:02
【问题描述】:
class UpdateIndexOnUsers < ActiveRecord::Migration
 def up
   sql = 'DROP INDEX index_users_on_email'
   sql << ' ON users' if Rails.env == 'production' # Heroku pg
   ActiveRecord::Base.connection.execute(sql)
 end
end

在 Heroku 上尝试 rake db:migrate 时出现语法错误。任何帮助将不胜感激。使用 Postgresql。我应该提到它在本地运行良好。

编辑:错误

PG::SyntaxError: Error: syntax error at or near "ON"
Line 1: DROP INDEX index_users_on_email ON users
                                        ^

【问题讨论】:

  • 如果您可以发布错误会有所帮助

标签: ruby-on-rails ruby heroku devise


【解决方案1】:

最简单的方法是使用 rails 的助手并让他们处理数据库细节:

class UpdateIndexOnUsers < ActiveRecord::Migration
  def up
    remove_index :users, :email
  end
end

如果索引最初创建时使用的名称不是 rails 默认使用的名称,您可以这样做

class UpdateIndexOnUsers < ActiveRecord::Migration
  def up
    remove_index :users, :email, :name => 'name_of_index'
  end
end

【讨论】:

    【解决方案2】:

    据我所知,Postgresql 在删除索引时不支持(或不需要)ON xxxx。文档也没有提到它:

    http://www.postgresql.org/docs/9.2/static/sql-dropindex.html

    只需指定索引名称就可以了,尽管您可以使用架构名称对其进行限定,如果您有标准设置,则可能不需要这样做。

    如果您还在本地使用 postgresql,那么它可能正在工作,因为 ON users 仅在 rails env 为 production 时添加,而您可能在本地 development 中运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-06
      • 1970-01-01
      • 2011-05-24
      • 2012-09-02
      • 2013-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多