我正在嘗試與Twitter API交互以在我的網站上顯示user_timeline。PGError:操作符不存在:character varying = bigint
我跟着Twitter的整合railscasts.com視頻:http://railscasts.com/episodes/359-twitter-integration
我與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
這裏的遷移:
class CreateTimelines < ActiveRecord::Migration
def change
create_table :timelines do |t|
t.string :tweet_id
t.string :screen_name
t.text :content
t.timestamps
end
末 結束
,並顯示推文:
<div id="timeline">
<% Timeline.order("tweet_id desc").limit(3).each do |timeline| %>
<h3><%= timeline.content %></h3>
<p class="pull-right">
~ @<%= timeline.screen_name %>
</p>
<% end %>
</div>
這個想法是將推文存儲在數據庫中,這樣即使Twitter關閉,這也不會影響用戶看到最近的推文。
無論如何,當我在控制檯中運行命令Timeline.pull_tweets
它工作正常。
這是當我推到heroku,遷移數據庫,並嘗試運行相同的命令。
然後我得到這個錯誤:
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.
與正在發生的事情任何幫助嗎?
我也嘗試過運行遷移,因此:tweet_id
是一個整數,但我在heroku上又遇到了一個錯誤。
謝謝。
我真的很想試試,但我厭倦了推動Heroku多次測試。永遠。使用to_s工作和控制檯命令在Heroku上工作。非常感謝,並且我計劃在本地安裝PostgreSQL。剛拿到一臺Mac w/Retina,無法讓Postgre安裝在我的2008 Mac上工作。再次感謝 – Jack