I'm trying to move data from one table to another during a migration while adding the new columns. My user model had the column phone, and phone_permission, which I'd like to move to the gallery model (including its data). My code:
def self.up
add_column :galleries, :phone, :string
add_column :galleries, :phone_permission, :integer, default: 1
execute "UPDATE galleries AS g, users AS u SET g.phone = u.phone WHERE u.id = g.user_id"
execute "UPDATE galleries AS g, users AS u SET g.phone_permission = u.phone_permission WHERE u.id = g.user_id"
remove_column :users, :phone
remove_column :users, :phone_permission
end
Error: SQLite3::SQLException: near "AS": syntax error: UPDATE galleries AS g, users AS u SET g.phone = u.phone WHERE u.id = g.user_id
Thanks for your help!