Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails PGError:运算符不存在:字符变化=bigint_Ruby On Rails_Sqlite_Postgresql_Heroku_Twitter - Fatal编程技术网

Ruby on rails PGError:运算符不存在:字符变化=bigint

Ruby 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

我正在尝试与Twitter API交互,以便在我的网站上显示用户的时间线

我观看了railscasts.com视频,了解Twitter集成:

我与API的交互很好,将信息拉到我的应用程序中,它在开发中显示和工作

我的代码如下:

模型-timeline.rb

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中的AKA
varchar(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
而不是当前字符串,您有几个选项:

  • 删除并重新创建具有正确架构的表。这将正常工作,但您将丢失所有数据
  • 手动发出一个命令,告诉PostgreSQL如何将字符串转换为整数

  • 一旦你弄明白了这一点,如果你打算部署到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,
        ...