1

I had already ran "$rails generate paperclip pin image" but decided to reinstall it to attempt to resolve "Could Not Run The Identify Command. Please Install ImageMagick." error while uploading image.

Thus went to terminal and ran "$ rails generate paperclip pin image --force" but ran into a problem I cant resolve. Pls help!

Steven-Lims-MacBook-Pro:Pinteresting stevenlim$ rake db:migrate
==  AddAttachmentImageToPins: migrating =======================================
-- change_table(:pins)
rake aborted!

An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: duplicate column name: image_file_name: ALTER TABLE "pins" ADD "image_file_name" varchar(255)/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:91:in `initialize'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:91:in `new'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:91:in `prepare'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:134:in `execute'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:331:in `block in execute'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_adapter.rb:435:in `block in log'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_adapter.rb:430:in `log'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:331:in `execute'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/schema_statements.rb:360:in `add_column'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:454:in `add_column'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/schema_definitions.rb:360:in `column'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/paperclip-3.5.4/lib/paperclip/schema.rb:52:in `block (2 levels) in attachment'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/paperclip-3.5.4/lib/paperclip/schema.rb:51:in `each_pair'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/paperclip-3.5.4/lib/paperclip/schema.rb:51:in `block in attachment'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/paperclip-3.5.4/lib/paperclip/schema.rb:50:in `each'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/paperclip-3.5.4/lib/paperclip/schema.rb:50:in `attachment'
/Users/stevenlim/Desktop/pinteresting/db/migrate/20140216024257_add_attachment_image_to_pins.rb:4:in `block in up'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/schema_statements.rb:334:in `change_table'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:625:in `block in method_missing'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:597:in `block in say_with_time'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:597:in `say_with_time'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:617:in `method_missing'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:383:in `method_missing'
/Users/stevenlim/Desktop/pinteresting/db/migrate/20140216024257_add_attachment_image_to_pins.rb:3:in `up'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:534:in `up'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:574:in `exec_migration'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:555:in `block (2 levels) in migrate'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:554:in `block in migrate'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:553:in `migrate'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:709:in `migrate'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:959:in `block in execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:1005:in `block in ddl_transaction'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `block in transaction'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:210:in `within_new_transaction'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `transaction'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/transactions.rb:209:in `transaction'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:1005:in `ddl_transaction'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:958:in `execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:920:in `block in migrate'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:916:in `each'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:916:in `migrate'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:764:in `up'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:742:in `migrate'
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/railties/databases.rake:42:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

STATUS

Steven-Lims-MacBook-Pro:Pinteresting stevenlim$ rake db:migrate:status

database: /Users/stevenlim/Desktop/pinteresting/db/development.sqlite3

 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20140205132449  Devise create users
   up     20140210143217  Create pins
   up     20140212145812  Add user id to pins
   up     20140215161350  ********** NO FILE **********
  down    20140216134900  Add attachment image to pins
Steven L
  • 131
  • 1
  • 3
  • 10
  • ImageMagick is a prerequisite for Paperclip gem. Paperclip would work only if ImageMagick is installed on your system and Paperclip has access to it. Looking at your error it seems like ImageMagick is not installed on your system. – Kirti Thorat Feb 16 '14 at 03:39

3 Answers3

1

ImageMagick is a prerequisite for Paperclip gem. Paperclip would work only if ImageMagick is installed on your system and Paperclip has access to it. Looking at your error "Could Not Run The Identify Command. Please Install ImageMagick." it seems like ImageMagick is not installed on your system. First step is to install it or check if it's installed then in your environment config file, let Paperclip know where to look for ImageMagick by adding ImageMagick path to it.

For eg: In development mode, you might add this line to config/environments/development.rb

Paperclip.options[:command_path] = write_your_imagemagick_path

Where You can get ImageMagick path by running which convert

Looking at the second error which you got, it seems like you already ran the migration once before, hence, the paperclip attachment related fields like image_file_name are already created in database table pins. And as you are trying to run that migration again you are getting duplicate column name error.

EDIT:

When you generated the paperclip pin image for the first time, one migration file was created under db/migrations which looking at the error I am assuming that you ran using rake db:migrate which is why you already have Paperclip image related columns in your pins table.

Later when you generated the paperclip pin image for the second time another migration file is created with the same column names which when you run using rake db:migrate is obviously going to yield duplicate column error.

You can just delete this second migration file, you don't need to run it as the columns are already created in database.

BUT if you still want to run the second migration file itself then first do rake db:rollback till the step where you ran the first migration so the image related columns would be removed from database. Then delete the first migration file and run rake db: migrate Which would run the second migration file and create the image related columns for you in the pins table.

Kirti Thorat
  • 52,578
  • 9
  • 101
  • 108
  • Hi @Kirti Thorat. Thanks for looking at this. in my db/migrate, i have the migration file already. I have ran rake db:migrate:status, the status is down for paperclip pin image. Have tried to do rake db:migrate:up VERSION= but the same error (duplicate column) occured – Steven L Feb 16 '14 at 13:51
  • You are getting that error because you already have the columns in your pins table. You can verify that by checking the pins table schema in database. `rake db:migrate` would only be successful if you `remove those existing columns` from the `pins table` either manually(directly remove columns from database by going in `rails dbconsole`) or by using `rake db:rollback`. – Kirti Thorat Feb 16 '14 at 14:21
  • I see @Kirti. I have pasted the db:migrate:status on top. How to I change the status from down to up? Also, how do I delete the migration ID 20140215161350 which has no file? – Steven L Feb 17 '14 at 01:51
1

I can't post comment (as I must have 50 rep). All you you need to do is delete that number from your schema_migrations table in the database.

HackerKarma
  • 620
  • 7
  • 18
1

@baloo, @user3317140 - Thanks for the help. I managed to solve this after many trial and error and hope this will help others facing same problem.

To delete the Migration ID: 20140215161350 Migration name: ********** NO FILE **********, I went to create 20140215161350_create_nothing.rb with the code class CreateNothing < ActiveRecord::Migration def change end end.

This allows migration name to be found and I thereafter ran rake:db:rollback.

I did another rake:db:rollback for the $ rails generate paperclip pin image.

All clean now. Back to the ImageMagick problem.

z atef
  • 7,138
  • 3
  • 55
  • 50
Steven L
  • 131
  • 1
  • 3
  • 10