Error

Failure/Error: _query(sql, @query_options.merge(options))

ActiveRecord::StatementInvalid:

Mysql2::Error: This connection is in use by: #


Solution

Add dependent: :destroy to the has_one_attached macro for ActiveRecord models