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
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.
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.
#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.
Related
I'm getting this error after trying to update a gem (mailboxer) and removing it.
Mysql2::Error: Table 'conversations' already exists: CREATE TABLE conversations (id int(11) DEFAULT NULL auto_increment PRIMARY KEY, subject varchar(255) DEFAULT '', created_at datetime NOT NULL, updated_at datetime NOT NULL)
I tried:
Bundle exec rake db:migrate rollback then rake db:migrate
Bundle exec rake db:migrate v= xxxxxxxx then rake db:migrate
getting rid of the migration files (that worked but I don't like the though of just getting rid of code)
I do not want to loose my data and drop the tables.
Any thoughts?
Update:
Rake db:migrate:status
up 20140526010413 Adduserfollowme to users
up 20140703193119 Add vote weight to votes
up 20140713211140 Add partime to user
up 20140716024440 Add devise to admin users
up 20140716024510 Create active admin comments
up 20140727042518 ********** NO FILE **********
up 20140727051902 Add slug to activities
down 20140728031732 Create mailboxer.mailboxer engine
down 20140728031733 Add notified object.mailboxer engine
down 20140728031734 Add notification code.mailboxer engine
down 20140728031735 Add attachments.mailboxer engine
down 20140728031736 Rename receipts read.mailboxer engine
down 20140728031737 Add global notification support.mailboxer engine
rake db:rollback
== AddSlugToActivities: reverting ============================================
-- remove_index("activities", {:column=>:slug})
-> 0.0215s
-- remove_column("activities", :slug)
-> 0.0342s
== AddSlugToActivities: reverted (0.0559s) ===================================
Rake db:migrate
== AddSlugToActivities: migrating ============================================
-- add_column(:activities, :slug, :string)
-> 0.0266s
-- add_index(:activities, :slug)
-> 0.0104s
== AddSlugToActivities: migrated (0.0373s) ===================================
== CreateMailboxer: migrating ================================================
-- create_table(:conversations)
rake aborted!
StandardError: An error has occurred, all later migrations canceled:
Mysql2::Error: Table 'conversations' already exists: CREATE TABLE `conversations` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `subject` varchar(255) DEFAULT '', `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL) ENGINE=InnoDB/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:in `query'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:in `block in execute'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:in `execute'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/mysql2_adapter.rb:211:in `execute'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/schema_statements.rb:170:in `create_table'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/foreigner-1.6.1/lib/foreigner/connection_adapters/abstract/schema_statements.rb:14:in `create_table'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:432:in `create_table'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:466:in `block in method_missing'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:438:in `block in say_with_time'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:438:in `say_with_time'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:458:in `method_missing'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:334:in `method_missing'
/home/bill/apps/woomatch/releases/20140728100705/db/migrate/20140728031732_create_mailboxer.mailboxer_engine.rb:6:in `up'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:370:in `up'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:410:in `block (2 levels) in migrate'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:410:in `block in migrate'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:129:in `with_connection'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:389:in `migrate'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:528:in `migrate'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:720:in `block (2 levels) in migrate'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:777:in `call'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:777:in `ddl_transaction'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:719:in `block in migrate'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:700:in `each'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:700:in `migrate'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:570:in `up'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/migration.rb:551:in `migrate'
/home/bill/apps/woomatch/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/railties/databases.rake:179:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
What should I do next?
There is no rake db:migrate rollback, only rake db:rollback
Try rake db:migrate:status, then use rake db:rollback to make unwanted migrations to be down.
Sometimes when 'something went wrong' and you migrate-rollback a lot, it is necessary to comment up some lines, make migrate\rollback and incomment them again.
If it doesnt work, try show code of migrations that fail
I am getting the following error when trying to run heroku run rake db:migrate. I have tried heroku pg:reset, I have tried heroku restart. I also tried creating a new app and starting over, but the problem persists. What could be the problem here?
Running `rake db:migrate` attached to terminal... up, run.7662
Migrating to CreateChannels (20140424224543)
== CreateChannels: migrating =================================================
-- create_table(:channels)
PG::DataCorrupted: ERROR: could not read block 0 in file "base/57396/12684": read only 0 of 8192 bytes
: CREATE TABLE "channels" ("id" serial primary key, "name" character varying(255), "user_id" integer, "created_at" timestamp, "updated_at" timestamp)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
PG::DataCorrupted: ERROR: could not read block 0 in file "base/57396/12684": read only 0 of 8192 bytes
: CREATE TABLE "channels" ("id" serial primary key, "name" character varying(255), "user_id" integer, "created_at" timestamp, "updated_at" timestamp) /app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `async_exec'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `block in execute'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_adapter.rb:435:in `block in log'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_adapter.rb:430:in `log'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/postgresql/database_statements.rb:127:in `execute'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/schema_statements.rb:190:in `create_table'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/migration.rb:625:in `block in method_missing'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/migration.rb:597:in `block in say_with_time'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/migration.rb:597:in `say_with_time'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/migration.rb:617:in `method_missing'
/app/db/migrate/20140424224543_create_channels.rb:3:in `change'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/migration.rb:571:in `exec_migration'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/migration.rb:555:in `block (2 levels) in migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/migration.rb:554:in `block in migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/migration.rb:553:in `migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/migration.rb:709:in `migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/migration.rb:959:in `block in execute_migration_in_transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/migration.rb:1005:in `block in ddl_transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `block in transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:210:in `within_new_transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/transactions.rb:209:in `transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/migration.rb:1005:in `ddl_transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/migration.rb:958:in `execute_migration_in_transaction'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/migration.rb:920:in `block in migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/migration.rb:916:in `each'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/migration.rb:916:in `migrate'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/migration.rb:764:in `up'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/migration.rb:742:in `migrate'
/app/vendor/bundle/ruby/2.0.0/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)
[Edit] My migration file for creating the channels table looks like the following (Nothing out of the ordinary)
class CreateChannels < ActiveRecord::Migration
def change
create_table :channels do |t|
t.string :name
t.integer :user_id
t.timestamps
end
end
end
I had the same issue, I deleted the database from https://dashboard.heroku.com/apps (this was Navy)
Added a new PG Database (this was blue)
From the terminal ran:
heroku config
You should see your db url
heroku config:set DATABASE_URL=postgres://your-db-url
Ran
heroku run rake db:migrate
And everything worked.
I am still not sure why that happened!
I contacted heroku support team last night, I was having the same issue, everything is back to normal now. bellow is their response.
Unfortunately, it looks like there was an issue with your database
last night which caused an outage for a couple hours, however it's
since been recovered by one of our on-call database engineers. This
issue wasn't caused by you at all, it was a hardware failure on the
host server.
Hope this helps.
I'm now having the same issue. I didn't have any production data so will just set up a new database. Very annoying though
Edit: Has just fixed itself when I ran the migration again
Edit 2: Is still broken. When I tried to run my second migration file I get the error
PG::DataCorrupted: ERROR: could not read block 1 in file "base/117039/12684": read only 0 of 8192 bytes
Very annoying
Just tried to file a ticket on Heroku. Filled out the form with loads of information and submitted only to get a message to say that I have not created any support tickets!
A few days ago I created a migration for rails to add Paperclip avatars, but ended up going a different direction. Being new to Rails, I didn't know how bad of an idea it was to delete the migration file like I did.
My app works fine locally, but when run heroku run rake db:migrate I get this:
undefined method `attachment' for #<ActiveRecord::ConnectionAdapters::Table:0x000000046092e0>
It is because it is trying to run a migration called AddAttachmentAvatarToVenues, which is the migration I stupidly deleted.
It was also adding columns for the avatars that were specified in the deleted migration to the schema.rb, but I created a new migration to get rid of these. The new migration got rid of them but didn't change the heroku migration error.
Any idea how to fix this? I've done lots of googling and looking around SO and while there a lot of people with similar errors they are mostly problems with the commands that they're using.
Here is the output after the deleted migration attempted in my heroku migration.
== AddAttachmentAvatarToVenues: migrating ====================================
-- change_table(:venues)
rake aborted!
An error has occurred, this and all later migrations canceled:
undefined method `attachment' for #<ActiveRecord::ConnectionAdapters::Table:0x00000003bdb7c8>
/app/db/migrate/20130206222434_add_attachment_avatar_to_venues.rb:4:in `block in up'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/schema_statements.rb:243:in `change_table'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:466:in `block in method_missing'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:438:in `block in say_with_time'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:438:in `say_with_time'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:458:in `method_missing'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:334:in `method_missing'
/app/db/migrate/20130206222434_add_attachment_avatar_to_venues.rb:3:in `up'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:370:in `up'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:410:in `block (2 levels) in migrate'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:410:in `block in migrate'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:129:in `with_connection'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:389:in `migrate'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:528:in `migrate'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:720:in `block (2 levels) in migrate'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:775:in `call'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:775:in `block in ddl_transaction'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/transactions.rb:208:in `transaction'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:775:in `ddl_transaction'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:719:in `block in migrate'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:700:in `each'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:700:in `migrate'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:570:in `up'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/migration.rb:551:in `migrate'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/railties/databases.rake:179:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
I do see what's wrong with the output, I'm just not sure how to fix it without messing it up more.
EDIT: Here's some screenshots of file structure:
(The two similarly named ones are because there was a column I forgot to remove, but this was after I was having this problem and didn't affect it either way)
EDIT2:
Here's the deleted migration from my git history. I had added some more channels after this. They were just a couple of strings, but if that could make a difference I'll find a newer version.
class AddAttachmentAvatarToVenues < ActiveRecord::Migration
def self.up
change_table :venues do |t|
t.attachment :avatar
end
end
def self.down
drop_attached_file :venues, :avatar
end
end
Thanks in advance!
Perhaps you should look into this: How to empty DB in heroku
All your normal commands are also available in heroku, the only difference is that you have to put heroku run in front of it.
If your application hasn't gone live yet you could simply reset the database:
heroku pg:reset SHARED_DATABASE --confirm NAME_OF_THE_APP
And recreate it, using:
heroku run rake db:migrate
To seed the database:
heroku run rake db:seed
And lastly, to restart Heroku:
heroku restart
P.S. If these steps don't help, you could try running "heroku run rake db:setup" after dropping the database
I have a very annoying problem with my migrations.
First the Errormessage:
bundle exec rake db:migrate --trace
(in /home/myhomefolder/msdnaa)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
rake aborted!
An error has occurred, all later migrations canceled:
uninitialized constant Computers
Now i have the assumption that an Update made by one of our admins is the reason why this happens every time. Even if there are no migrations at all!
What i've done (besides searching on Stack Overflow for a solution) is to grep every single file for "Computers".
Of course there are some Files containing this word and i checked them for Syntax Errors and the usual Stuff like missing ":".
Then i asked a workmate for some help (he is much more skilled with ruby than i am) and he hasn't a clue, everything looks right.
I'm using a slightly old Version of Ruby (1.8.7) and Rails (3.0.9), but i have no rights to do an update on our Server, so i have to deal with it.
And yes i asked the admin to do an update to 1.9.x and 3.1.x, but that can't be the fault 'cause it worked fine last week.
So it's one of those Errors where it SHOULD work, but it doesn't and i bet the solution is easy as drinking water, but i don't see it!
Any suggestions?
EDIT: Here ist the --trace:
/var/lib/gems/1.8/gems/activesupport-3.0.9/lib/active_support/inflector/meth ods.rb:113:in `constantize'
/var/lib/gems/1.8/gems/activesupport-3.0.9/lib/active_support/inflector/meth ods.rb:112:in `each'
/var/lib/gems/1.8/gems/activesupport-3.0.9/lib/active_support/inflector/meth ods.rb:112:in `constantize'
/var/lib/gems/1.8/gems/activesupport-3.0.9/lib/active_support/core_ext/strin g/inflections.rb:43:in `constantize'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:407 :in `load_migration'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:402 :in `migration'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:397 :in `migrate'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:539 :in `migrate'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:615 :in `call'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:615 :in `ddl_transaction'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:538 :in `migrate'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:525 :in `each'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:525 :in `migrate'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:435 :in `up'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/migration.rb:417 :in `migrate'
/var/lib/gems/1.8/gems/activerecord-3.0.9/lib/active_record/railties/databas es.rake:142
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:205:in `call'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:205:in `execute'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:200:in `each'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:158:in `invoke_with_call_ chain'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_ chain'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:112:in `invoke_tas k'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:90:in `top_level'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:90:in `each'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:90:in `top_level'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_e xception_handling'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:84:in `top_level'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:62:in `run'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_e xception_handling'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
/var/lib/gems/1.8/gems/rake-0.9.2/bin/rake:32
/var/lib/gems/1.8/bin/rake:19:in `load'
/var/lib/gems/1.8/bin/rake:19
Tasks: TOP => db:migrate
My guess is that you have just added a migration called something like 20120221123456_computers.rb, and within it, you have something like...
class SomeNameThatsNotComputers < ActiveRecord::Migration
...
When Rails executes a migration, it expects to execute the file, which defines the class, and then instantiate the class, and call #up or #down on that class instance. How does Rails know what class to instantiate? It's supposed to correspond with the part of the file name following the numeric prefix and underscore, so for a file name like 20120221123456_computers.rb, the class name must be Computers.
As you said grep tells existence of "Computers" that's the problem. It means Computers is not defined but getting used. migration loads the app environment first and that time it fails bcoz Computers is not initialized
I am trying to run ruby on rails code that I got from github and I ended up installing mysql using homebrew and then also ended up installing it directly from http://dev.mysql.com/. It was only then that when I used rake in the application file that the tests began to run. However, now I keep getting this Mysql2::Error: Duplicate entry and I don't understand why. Could it be the fact that I have two mysqls located two different places on my computer? I am not really sure what is causing this problem because all the tables are empty. How can I fix this problem? Thank you for helping. I am new to Ruby on Rails and Mysql.
The stack looks like the following:
HomeControllerTest
test_should_get_index ERROR
Mysql2::Error: Duplicate entry '' for key 'index_admin_users_on_email': INSERT INTO `admin_users` (`created_at`, `updated_at`, `id`) VALUES ('2011-12-09 09:33:30', '2011-12-09 09:33:30', 298486374)
STDERR:
Exception `ActiveRecord::RecordNotUnique' at /Users/nick01s/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/connection_adapters/mysql2_adapter.rb:283:in `query'
/Users/nick01s/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/connection_adapters/mysql2_adapter.rb:283:in `block in execute'
/Users/nick01s/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract_adapter.rb:244:in `block in log'
/Users/nick01s/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.1.3/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/Users/nick01s/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract_adapter.rb:239:in `log'
/Users/nick01s/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/connection_adapters/mysql2_adapter.rb:283:in `execute'
/Users/nick01s/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/database_statements.rb:302:in `insert_fixture'
/Users/nick01s/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/fixtures.rb:486:in `block (5 levels) in create_fixtures'
/Users/nick01s/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/fixtures.rb:485:in `each'
/Users/nick01s/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/fixtures.rb:485:in `block (4 levels) in create_fixtures'
/Users/nick01s/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/fixtures.rb:484:in `each'
/Users/nick01s/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/fixtures.rb:484:in `block (3 levels) in create_fixtures'
/Users/nick01s/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/fixtures.rb:476:in `each'
/Users/nick01s/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/fixtures.rb:476:in `block (2 levels) in create_fixtures'
/Users/nick01s/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
/Users/nick01s/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/fixtures.rb:475:in `block in create_fixtures'
/Users/nick01s/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/connection_adapters/mysql2_adapter.rb:202:in `disable_referential_integrity'
/Users/nick01s/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/fixtures.rb:460:in `create_fixtures'
/Users/nick01s/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/fixtures.rb:924:in `load_fixtures'
/Users/nick01s/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/fixtures.rb:890:in `setup_fixtures'
/Users/nick01s/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:413:in `_run_setup_callbacks'
/Users/nick01s/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:81:in `run_callbacks'
/Users/nick01s/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.1.3/lib/active_support/testing/setup_and_teardown.rb:34:in `run'
For anyone else getting this error, this came down to (for me) installing active_admin into an existing project.
The admin_users.yml fixture file was initialised by rails to insert two empty records:
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
Commenting out/removing these empty insertions fixed the error for me.
It's unlikely that the two installations of mysql are causing this problem. Rails should only connect to one database. You may not know which one it is connecting to, but it takes extra work to get it to connect to more than one db.
I've seen that duplicate key error before when the fixtures in tests were bad.
In your stack trace, it looks to me like something (fixtures or factories) is trying to create an admin_user without a required field. Twice.
The second time it's throwing an exception because the index is set to unique.