heroku 运行 rake db:migrate,未定义的方法
heroku run rake db:migrate, undefined method
当我尝试将我的数据库迁移到 heroku 时,出现此错误。我认为这可能与回形针有关。当我在我的计算机上本地收集我的数据库时,它工作正常。
错误信息
Running `rake db:migrate` attached to terminal... up, run.2870
(705.4ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL)
(59.9ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
ActiveRecord::SchemaMigration Load (2.7ms) SELECT "schema_migrations".* FROM "schema_migrations"
Migrating to CreateCountries (20150113022256)
(3.2ms) BEGIN
== 20150113022256 CreateCountries: migrating ==================================
-- create_table(:countries)
(4.1ms) ROLLBACK
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
undefined method `attachment' for #<ActiveRecord::ConnectionAdapters::PostgreSQL::TableDefinition:0x007fb245cca098>/app/db/migrate/20150113022256_create_countries.rb:6:in `block in change'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:200:in `create_table'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:662:in `block in method_missing'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:632:in `block in say_with_time'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:632:in `say_with_time'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:652:in `method_missing'
/app/db/migrate/20150113022256_create_countries.rb:3:in `change'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:606:in `exec_migration'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:590:in `block (2 levels) in migrate'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:589:in `block in migrate'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in `with_connection'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:588:in `migrate'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:765:in `migrate'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:995:in `block in execute_migration_in_transaction'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:1041:in `block in ddl_transaction'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/transactions.rb:220:in `transaction'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:1041:in `ddl_transaction'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:994:in `execute_migration_in_transaction'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:956:in `block in migrate'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:952:in `each'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:952:in `migrate'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:820:in `up'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:798:in `migrate'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
NoMethodError: undefined method `attachment' for #<ActiveRecord::ConnectionAdapters::PostgreSQL::TableDefinition:0x007fb245cca098>
/app/db/migrate/20150113022256_create_countries.rb:6:in `block in change'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:200:in `create_table'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:662:in `block in method_missing'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:632:in `block in say_with_time'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:632:in `say_with_time'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:652:in `method_missing'
/app/db/migrate/20150113022256_create_countries.rb:3:in `change'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:606:in `exec_migration'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:590:in `block (2 levels) in migrate'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:589:in `block in migrate'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in `with_connection'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:588:in `migrate'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:765:in `migrate'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:995:in `block in execute_migration_in_transaction'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:1041:in `block in ddl_transaction'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/transactions.rb:220:in `transaction'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:1041:in `ddl_transaction'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:994:in `execute_migration_in_transaction'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:956:in `block in migrate'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:952:in `each'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:952:in `migrate'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:820:in `up'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:798:in `migrate'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
20150113022256_create_countries.rb
class CreateCountries < ActiveRecord::Migration
def change
create_table :countries do |t|
t.string :text
t.string :title
t.attachment :photo
t.timestamps null: false
end
end
end
Gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.0'
# Use sqlite3 as the database for Active Record
group :development, :test do
gem 'sqlite3'
end
gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'jquery-turbolinks'
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'rails_12factor', group: :production
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'paperclip'
ruby '2.2.0'
end
您在 development
和 test
组中有 gem 'paperclip'
。这意味着,这不包含在您的生产环境中。将 gem 'paperclip'
声明移出 group :development, :test do ...
块。
当我尝试将我的数据库迁移到 heroku 时,出现此错误。我认为这可能与回形针有关。当我在我的计算机上本地收集我的数据库时,它工作正常。
错误信息
Running `rake db:migrate` attached to terminal... up, run.2870
(705.4ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL)
(59.9ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
ActiveRecord::SchemaMigration Load (2.7ms) SELECT "schema_migrations".* FROM "schema_migrations"
Migrating to CreateCountries (20150113022256)
(3.2ms) BEGIN
== 20150113022256 CreateCountries: migrating ==================================
-- create_table(:countries)
(4.1ms) ROLLBACK
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
undefined method `attachment' for #<ActiveRecord::ConnectionAdapters::PostgreSQL::TableDefinition:0x007fb245cca098>/app/db/migrate/20150113022256_create_countries.rb:6:in `block in change'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:200:in `create_table'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:662:in `block in method_missing'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:632:in `block in say_with_time'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:632:in `say_with_time'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:652:in `method_missing'
/app/db/migrate/20150113022256_create_countries.rb:3:in `change'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:606:in `exec_migration'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:590:in `block (2 levels) in migrate'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:589:in `block in migrate'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in `with_connection'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:588:in `migrate'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:765:in `migrate'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:995:in `block in execute_migration_in_transaction'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:1041:in `block in ddl_transaction'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/transactions.rb:220:in `transaction'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:1041:in `ddl_transaction'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:994:in `execute_migration_in_transaction'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:956:in `block in migrate'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:952:in `each'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:952:in `migrate'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:820:in `up'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:798:in `migrate'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
NoMethodError: undefined method `attachment' for #<ActiveRecord::ConnectionAdapters::PostgreSQL::TableDefinition:0x007fb245cca098>
/app/db/migrate/20150113022256_create_countries.rb:6:in `block in change'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:200:in `create_table'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:662:in `block in method_missing'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:632:in `block in say_with_time'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:632:in `say_with_time'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:652:in `method_missing'
/app/db/migrate/20150113022256_create_countries.rb:3:in `change'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:606:in `exec_migration'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:590:in `block (2 levels) in migrate'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:589:in `block in migrate'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in `with_connection'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:588:in `migrate'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:765:in `migrate'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:995:in `block in execute_migration_in_transaction'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:1041:in `block in ddl_transaction'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/transactions.rb:220:in `transaction'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:1041:in `ddl_transaction'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:994:in `execute_migration_in_transaction'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:956:in `block in migrate'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:952:in `each'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:952:in `migrate'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:820:in `up'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:798:in `migrate'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
20150113022256_create_countries.rb
class CreateCountries < ActiveRecord::Migration
def change
create_table :countries do |t|
t.string :text
t.string :title
t.attachment :photo
t.timestamps null: false
end
end
end
Gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.0'
# Use sqlite3 as the database for Active Record
group :development, :test do
gem 'sqlite3'
end
gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'jquery-turbolinks'
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'rails_12factor', group: :production
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'paperclip'
ruby '2.2.0'
end
您在 development
和 test
组中有 gem 'paperclip'
。这意味着,这不包含在您的生产环境中。将 gem 'paperclip'
声明移出 group :development, :test do ...
块。