LoginSignup
1
2

More than 5 years have passed since last update.

RailsでページビューをカウントするimpressionistでMySQLエラーが出た時の回避法

Posted at

Railsで開発途中のアプリケーションにページビュー機能を付けるgemimpressionist使用した際に起きた問題の回避方法のメモ

環境

  • Ruby 2.4系
  • Rails 5.0系
  • MySQL 5.7系

発生した問題

impressionistについて調べると、Gemfileに以下のように記述されている例が紹介されている。

# 一般的なgemの指定方法
gem 'impressionist'

# バージョンを指定した方法
gem 'impressionist', '~> 1.5.1'

以上の方法でrake db:migrateをするとMySQL Errorで以下のようなメッセージが出る。

StandardError: An error has occurred, all later migrations canceled:

Mysql2::Error: BLOB/TEXT column 'params' used in key specification without a key length: CREATE  INDEX `poly_params_request_index`  ON `impressions` (`impressionable_type`, `impressionable_id`, `params`)

回避方法

以下のような手順で回避出来る。

Gemfileに以下のように記述

gem 'impressionist', git: 'https://github.com/charlotte-ruby/impressionist.git'

以上記述したら、bundle installを行い、rails g impressionistrake db:migrateを行う一連の流れのまま進められる。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2