Error in migration - Error: You have an error in your SQL syntax; check the manual that corresponds

Cant undestand what wrong with syntax sql file migration. please, help:

i run rake:db:migrate

error:

Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘)’ at line 1: UPDATE photos SET votes_count = 0, rating = 0 WHERE id NOT IN ()/home/user/myapp/appmame/db/migrate/20131110162613_recalculate_photos_rating.rb:8:in `up’

class RecalculatePhotosRating < ActiveRecord::Migration def up if Vote.where(“subject_type=‘Photo’ and rating > 1”).count > 0 ActiveRecord::Base.connection.execute “DELETE FROM votes WHERE subject_type=‘Photo’ AND rating <= 5” ActiveRecord::Base.connection.execute “UPDATE votes SET rating=1 WHERE subject_type=‘Photo’” end pids = Vote.where(subject_type: ‘Photo’).pluck(:subject_id).uniq ActiveRecord::Base.connection.execute “UPDATE photos SET votes_count = 0, rating = 0 WHERE id NOT IN (#{pids.join(', ')})” ActiveRecord::Base.connection.execute “UPDATE photos SET rating=(SELECT COUNT() FROM votes WHERE votes.subject_type=‘Photo’ AND subject_id=photos.id) WHERE id IN (#{pids.join(', ')})" ActiveRecord::Base.connection.execute "UPDATE photos SET votes_count=(SELECT COUNT() FROM votes WHERE votes.subject_type=‘Photo’ AND subject_id=photos.id) WHERE id IN (#{pids.join(', ')})” end

def down end end

``

i inserted

pids = Vote.where(subject_type: 'Photo').pluck(:subject_id).    uniq
unless pids.empty?

but again same error

now work. thank you