【问题标题】:AuthLogic + PostgreSQL 8.4: persistence_token defined as a string, then used as integerAuthLogic + PostgreSQL 8.4:persistence_token 定义为字符串,然后用作整数
【发布时间】:2010-11-29 04:25:14
【问题描述】:

我正在尝试将 AuthLogic 集成到我的 rails 应用程序中,并且我遵循了将 persistence_token 定义为字符串的示例:

https://github.com/binarylogic/authlogic_example

但是,当我在 ubuntu 桌面上使用 PostgreSQL 8.4 运行它时,出现以下错误:

ActiveRecord::StatementInvalid in UsersController#index

PGError: ERROR:  operator does not exist: character varying = integer
LINE 1: ...* FROM "users" WHERE ("users"."persistence_token" = 21007622...
                                                             ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
: SELECT * FROM "users" WHERE ("users"."persistence_token" = 2100762299)  LIMIT 1

我尝试将 persistence_token 更改为整数,但 AuthLogic 的其他部分似乎没有更新它。

我确定这一定是一个常见问题,但谷歌搜索并不是很有帮助,有什么想法可以解决这个问题吗?

Ruby 版本:1.8.7 导轨版本:2.3.5 AuthLogic 版本:2.1.6

【问题讨论】:

  • 我第一次尝试 Authlogic 时遇到了同样的问题。我找不到真正的解决方案,但从头开始重新启动项目为我解决了这个问题。
  • 我们也有这个问题,但仅在使用 rspec 进行测试时。实际的应用程序运行良好。
  • 什么版本的 Ruby? Rails 似乎需要 1.8.7 或 1.9.2。什么版本的 Rails? 3.0.3 似乎是当前版本。什么版本的 AuthLogic? 2.1.6 似乎是最新的。 PostgreSQL 版本为 9.0.2,但我怀疑这是您问题的根源。
  • @Catcall:我将这些版本号添加到原始问题中
  • 你找到答案了吗?我也遇到了同样的问题

标签: ruby-on-rails postgresql authlogic


【解决方案1】:

这是一个问题,因为表中的行的“persistence_token”值为 nil。将列设置为一个值将导致此错误消失。我怀疑这与 rails 检查表列的方式及其与 authlogic 的交互有关。

【讨论】:

    【解决方案2】:

    你能展示声明persistence_token的代码吗?

    我会先尝试类型转换和转换。在 SQL 方面,所有这些都可以工作。

     WHERE ("users"."persistence_token" = cast(2100762299 as varchar))
     WHERE ("users"."persistence_token" = 2100762299::text)
     WHERE ("users"."persistence_token" = text(2100762299))
     WHERE ("users"."persistence_token" = 2100762299 || '')
    

    最后一个是隐式类型强制。它通过将数字连接到空字符串来强制 PostgreSQL 将数字视为字符串。

    但您可能必须在运行时在 Ruby 中更改数据类型。

    yournumber.to_s
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-10-16
      • 2018-10-06
      • 1970-01-01
      • 1970-01-01
      • 2012-07-26
      • 2020-07-19
      • 1970-01-01
      相关资源
      最近更新 更多