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!
Related
I've been getting this persistent error every time I try to update my table in rails.
For example if my code in the schema.rb file is:
create_table "books", force: :cascade do |t|
t.string "title"
t.text "description"
t.datetime "created_at"
t.datetime "updated_at"
end
If I go into the rails console and write the command:
book = Book.new(title: "a book", description: "a book description")
it gives me the following error:
Errno::EBADF (Bad file descriptor)
from C:/Ruby27-x64/lib/ruby/2.7.0/irb/input-method.rb:42:in `winsize'
from C:/Ruby27-x64/lib/ruby/2.7.0/irb/input-method.rb:42:in `winsize'
from C:/Ruby27-x64/lib/ruby/2.7.0/irb.rb:753:in `output_value'
from C:/Ruby27-x64/lib/ruby/2.7.0/irb.rb:545:in `block (2 levels) in eval_input'
from C:/Ruby27-x64/lib/ruby/2.7.0/irb.rb:704:in `signal_status'
from C:/Ruby27-x64/lib/ruby/2.7.0/irb.rb:538:in `block in eval_input'
from C:/Ruby27-x64/lib/ruby/2.7.0/irb/ruby-lex.rb:166:in `block (2 levels) in each_top_level_statement'
from C:/Ruby27-x64/lib/ruby/2.7.0/irb/ruby-lex.rb:151:in `loop'
from C:/Ruby27-x64/lib/ruby/2.7.0/irb/ruby-lex.rb:151:in `block in each_top_level_statement'
from C:/Ruby27-x64/lib/ruby/2.7.0/irb/ruby-lex.rb:150:in `catch'
from C:/Ruby27-x64/lib/ruby/2.7.0/irb/ruby-lex.rb:150:in `each_top_level_statement'
from C:/Ruby27-x64/lib/ruby/2.7.0/irb.rb:537:in `eval_input'
from C:/Ruby27-x64/lib/ruby/2.7.0/irb.rb:472:in `block in run'
from C:/Ruby27-x64/lib/ruby/2.7.0/irb.rb:471:in `catch'
from C:/Ruby27-x64/lib/ruby/2.7.0/irb.rb:471:in `run'
from C:/Ruby27-x64/lib/ruby/2.7.0/irb.rb:400:in `start'
Maybe IRB bug!
I can continue and write book.save which will update the new book into the database however I not sure if this error message is a concern. It wasn't there previously when running this command and is now there on all projects when trying to update any tables.
I've completely reinstalled Ruby 2.7 and RubyMine and this error still returns. I'm not sure what this problem is caused by.
Thank you for any advice.
(Info: working on Windows machine on RubyMine. Using rails 5.2.4 and Ruby 2.7.1)
That appears to be a known problem with IRB and Ruby 2.7 so could you please add your vote there:
https://youtrack.jetbrains.com/issue/RUBY-26249
I'm trying to get a legacy Rails app up and running and when I do a
rake db:migrate
I get the following:
arx_rails [master●] % rake db:migrate
== AddSessionsTable: migrating ===============================================
-- create_table(:sessions)
rake aborted!
An error has occurred, all later migrations canceled:
Mysql2::Error: All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead: CREATE TABLE `sessions` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `session_id` varchar(255) NOT NULL, `data` text, `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL) ENGINE=InnoDB/Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:245:in `query'
/Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:245:in `block in execute'
/Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:245:in `execute'
/Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/mysql2_adapter.rb:211:in `execute'
/Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/schema_statements.rb:170:in `create_table'
/Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:434:in `create_table'
/Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/migration.rb:466:in `block in method_missing'
/Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/migration.rb:438:in `block in say_with_time'
/Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/migration.rb:438:in `say_with_time'
/Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/migration.rb:458:in `method_missing'
/Users/steve/projects/asu/arx_rails/db/migrate/20120825213542_add_sessions_table.rb:3:in `change'
/Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/migration.rb:407:in `block (2 levels) in migrate'
/Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/migration.rb:407:in `block in migrate'
/Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:123:in `with_connection'
/Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/migration.rb:389:in `migrate'
/Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/migration.rb:528:in `migrate'
/Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/migration.rb:720:in `block (2 levels) in migrate'
/Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/migration.rb:777:in `call'
/Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/migration.rb:777:in `ddl_transaction'
/Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/migration.rb:719:in `block in migrate'
/Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/migration.rb:700:in `each'
/Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/migration.rb:700:in `migrate'
/Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/migration.rb:570:in `up'
/Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/migration.rb:551:in `migrate'
/Users/steve/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/railties/databases.rake:153:in `block (2 levels) in <top (required)>'
/Users/steve/.rvm/gems/ruby-1.9.3-p194/bin/ruby_executable_hooks:15:in `eval'
/Users/steve/.rvm/gems/ruby-1.9.3-p194/bin/ruby_executable_hooks:15:in `<main>'
The migration file is:
class AddSessionsTable < ActiveRecord::Migration
def change
create_table :sessions do |t|
t.string :session_id, :null => false
t.text :data
t.timestamps
end
add_index :sessions, :session_id
add_index :sessions, :updated_at
end
end
Rails has always created the id field itself without having to have it explicitly coded in the migration file and that it makes it a primary key but without a default value. So, I'm wondering where it might be setting the id fields to a DEFAULT of NULL for newly created tables. In some configuration file somewhere I don't know about?
Has anyone seen this before?
It looks like an issue with Rails and MySQL:
https://github.com/rails/rails/pull/13247
In the notes, user "pjg" suggests the following:
With Rails 2.3.5, MySQL version 5.7.9 and mysql gem you need to have
this bit as an initializer in
config/initializers/abstract_mysql_adapter.rb:
class ActiveRecord::ConnectionAdapters::MysqlAdapter
NATIVE_DATABASE_TYPES[:primary_key] = "int(11) auto_increment PRIMARY KEY"
end
For mysql2 it should be
config/initializers/abstract_mysql2_adapter.rb:
class ActiveRecord::ConnectionAdapters::Mysql2Adapter
NATIVE_DATABASE_TYPES[:primary_key] = "int(11) auto_increment PRIMARY KEY"
end
Does that resolve the issue?
(EDIT: giving credit to solution provider)
For Rails 3.0.5 works that way:
class ActiveRecord::ConnectionAdapters::ColumnDefinition
def sql_type
type.to_sym == :primary_key ? 'int(11) auto_increment PRIMARY KEY' : base.type_to_sql(type.to_sym, limit, precision, scale) rescue type
end
end
With Rails 4.0.6 works fine:
config/initializers/abstract_mysql2_adapter.rb:
class ActiveRecord::ConnectionAdapters::Mysql2Adapter
NATIVE_DATABASE_TYPES[:primary_key] = "int(11) NOT NULL auto_increment PRIMARY KEY"
end
$ gem list mysql
* LOCAL GEMS *
mysql2 (0.3.18)
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 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.
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