Ruby on rails PGError:运算符不存在:字符变化=bigint
我正在尝试与Twitter API交互,以便在我的网站上显示用户的时间线 我观看了railscasts.com视频,了解Twitter集成: 我与API的交互很好,将信息拉到我的应用程序中,它在开发中显示和工作 我的代码如下: 模型-timeline.rbRuby on rails PGError:运算符不存在:字符变化=bigint,ruby-on-rails,sqlite,postgresql,heroku,twitter,Ruby On Rails,Sqlite,Postgresql,Heroku,Twitter,我正在尝试与Twitter API交互,以便在我的网站上显示用户的时间线 我观看了railscasts.com视频,了解Twitter集成: 我与API的交互很好,将信息拉到我的应用程序中,它在开发中显示和工作 我的代码如下: 模型-timeline.rb class Timeline < ActiveRecord::Base attr_accessible :content, :screen_name, :tweet_id def self.pull_tweets Twi
class Timeline < ActiveRecord::Base
attr_accessible :content, :screen_name, :tweet_id
def self.pull_tweets
Twitter.user_timeline("{username_goes_here}", since_id: maximum(:tweet_id)).each do |tweet|
unless exists?(tweet_id: tweet.id)
create!(
tweet_id: tweet.id,
content: tweet.text,
screen_name: tweet.user.screen_name,
)
end
end
end
end
有什么可以帮忙的吗
我还尝试运行迁移,以便:tweet\u id
是一个整数,但我在heroku上也遇到了另一个错误
谢谢。您已经创建了
tweet\u id
作为字符串(PostgreSQL中的AKAvarchar(255)
):
但是你的tweet.id
:
unless exists?(tweet_id: tweet.id)
实际上是一个数字。如果您想继续将您的tweet\u id
存储为一个字符串,那么您必须将id
转换为使用它的任何地方的字符串:
unless exists?(tweet_id: tweet.id.to_s)
create!(
tweet_id: tweet.id.to_s,
...
如果您想将生产表修改为使用整数作为tweet\u id
而不是当前字符串,您有几个选项:
一旦你弄明白了这一点,如果你打算部署到Heroku,你应该在本地安装PostgreSQL并在PostgreSQL之上开发。我本来打算尝试一下,但我已经厌倦了多次推到Heroku进行测试。需要永远。在Heroku上使用to_s工作,控制台命令工作。非常感谢,是的,我计划在本地安装PostgreSQL。刚买了一台带有视网膜的Mac电脑,无法在我2008年的Mac电脑上安装Postgre。再次感谢
PGError: ERROR: operator does not exist: character varying = bigint
LINE 1: ...ne FROM "timelines" WHERE "timelines"."tweet_id" = 21919081...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
create_table :timelines do |t|
t.string :tweet_id
unless exists?(tweet_id: tweet.id)
unless exists?(tweet_id: tweet.id.to_s)
create!(
tweet_id: tweet.id.to_s,
...