0

私はherokuにアプリケーションをデプロイしたいと思っていましたが、sqlite3はサポートしていませんでした。私は問題は、sqliteのために生成されたいくつかの移行はpgと互換性がないということだと思います。問題が発生するように見えるHeroku:Rails 5のデプロイメントエラー - dbの移行中にエラーが発生しました

Running rake db:migrate on ⬢ ground-tree... up, run.6485 
    D, [2016-07-08T19:02:25.697588 #3] DEBUG -- : (0.8ms) SELECT pg_try_advisory_lock(1215818661303848385); 
D, [2016-07-08T19:02:25.715589 #3] DEBUG -- : ActiveRecord::SchemaMigration Load (1.0ms) SELECT "schema_migrations".* FROM "schema_migrations" 
I, [2016-07-08T19:02:25.724349 #3] INFO -- : Migrating to AddWinnerToItems (20160706115655) 
D, [2016-07-08T19:02:25.726558 #3] DEBUG -- : (0.8ms) BEGIN 
== 20160706115655 AddWinnerToItems: migrating ================================= 
-- add_column(:items, :winner_id, :references, {:foreign_key=>true}) 
D, [2016-07-08T19:02:25.728658 #3] DEBUG -- : (1.5ms) ALTER TABLE "items" ADD "winner_id" references 
D, [2016-07-08T19:02:25.729640 #3] DEBUG -- : (0.7ms) ROLLBACK 
D, [2016-07-08T19:02:25.730786 #3] DEBUG -- : (0.8ms) SELECT pg_advisory_unlock(1215818661303848385) 
rake aborted! 
StandardError: An error has occurred, this and all later migrations canceled: 

PG::SyntaxError: ERROR: syntax error at or near "references" 
LINE 1: ALTER TABLE "items" ADD "winner_id" references 
              ^
: ALTER TABLE "items" ADD "winner_id" references 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:98:in `async_exec' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:98:in `block in execute' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:566:in `block in log' 
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.0/lib/active_support/notifications/instrumenter.rb:21:in `instrument' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:560:in `log' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:97:in `execute' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:547:in `add_column' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/postgresql/schema_statements.rb:471:in `add_column' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:845:in `block in method_missing' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:814:in `block in say_with_time' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:814:in `say_with_time' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:834:in `method_missing' 
/app/db/migrate/20160706115655_add_winner_to_items.rb:3:in `change' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:788:in `exec_migration' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:772:in `block (2 levels) in migrate' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:771:in `block in migrate' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:398:in `with_connection' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:770:in `migrate' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:950:in `migrate' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1211:in `block in execute_migration_in_transaction' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1279:in `block in ddl_transaction' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `block in transaction' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/transaction.rb:189:in `within_new_transaction' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `transaction' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/transactions.rb:211:in `transaction' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1279:in `ddl_transaction' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1210:in `execute_migration_in_transaction' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1183:in `block in migrate_without_lock' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1182:in `each' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1182:in `migrate_without_lock' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1131:in `block in migrate' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1298:in `with_advisory_lock' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1131:in `migrate' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1005:in `up' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:983:in `migrate' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/tasks/database_tasks.rb:161:in `migrate' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/railties/databases.rake:58:in `block (2 levels) in <top (required)>' 
/app/vendor/bundle/ruby/2.3.0/gems/rake-11.2.2/exe/rake:27:in `<top (required)>' 
ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR: syntax error at or near "references" 
LINE 1: ALTER TABLE "items" ADD "winner_id" references 
              ^
: ALTER TABLE "items" ADD "winner_id" references 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:98:in `async_exec' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:98:in `block in execute' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:566:in `block in log' 
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.0/lib/active_support/notifications/instrumenter.rb:21:in `instrument' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:560:in `log' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:97:in `execute' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:547:in `add_column' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/postgresql/schema_statements.rb:471:in `add_column' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:845:in `block in method_missing' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:814:in `block in say_with_time' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:814:in `say_with_time' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:834:in `method_missing' 
/app/db/migrate/20160706115655_add_winner_to_items.rb:3:in `change' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:788:in `exec_migration' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:772:in `block (2 levels) in migrate' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:771:in `block in migrate' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:398:in `with_connection' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:770:in `migrate' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:950:in `migrate' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1211:in `block in execute_migration_in_transaction' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1279:in `block in ddl_transaction' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `block in transaction' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/transaction.rb:189:in `within_new_transaction' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `transaction' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/transactions.rb:211:in `transaction' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1279:in `ddl_transaction' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1210:in `execute_migration_in_transaction' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1183:in `block in migrate_without_lock' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1182:in `each' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1182:in `migrate_without_lock' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1131:in `block in migrate' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1298:in `with_advisory_lock' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1131:in `migrate' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1005:in `up' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:983:in `migrate' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/tasks/database_tasks.rb:161:in `migrate' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/railties/databases.rake:58:in `block (2 levels) in <top (required)>' 
/app/vendor/bundle/ruby/2.3.0/gems/rake-11.2.2/exe/rake:27:in `<top (required)>' 
PG::SyntaxError: ERROR: syntax error at or near "references" 
LINE 1: ALTER TABLE "items" ADD "winner_id" references 
              ^
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:98:in `async_exec' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:98:in `block in execute' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:566:in `block in log' 
/app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.0.0/lib/active_support/notifications/instrumenter.rb:21:in `instrument' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:560:in `log' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:97:in `execute' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:547:in `add_column' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/postgresql/schema_statements.rb:471:in `add_column' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:845:in `block in method_missing' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:814:in `block in say_with_time' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:814:in `say_with_time' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:834:in `method_missing' 
/app/db/migrate/20160706115655_add_winner_to_items.rb:3:in `change' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:788:in `exec_migration' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:772:in `block (2 levels) in migrate' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:771:in `block in migrate' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:398:in `with_connection' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:770:in `migrate' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:950:in `migrate' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1211:in `block in execute_migration_in_transaction' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1279:in `block in ddl_transaction' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `block in transaction' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/transaction.rb:189:in `within_new_transaction' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `transaction' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/transactions.rb:211:in `transaction' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1279:in `ddl_transaction' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1210:in `execute_migration_in_transaction' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1183:in `block in migrate_without_lock' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1182:in `each' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1182:in `migrate_without_lock' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1131:in `block in migrate' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1298:in `with_advisory_lock' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1131:in `migrate' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:1005:in `up' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/migration.rb:983:in `migrate' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/tasks/database_tasks.rb:161:in `migrate' 
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.0/lib/active_record/railties/databases.rake:58:in `block (2 levels) in <top (required)>' 
/app/vendor/bundle/ruby/2.3.0/gems/rake-11.2.2/exe/rake:27:in `<top (required)>' 
Tasks: TOP => db:migrate 
(See full trace by running task with --trace) 

移行:

class AddWinnerToItems < ActiveRecord::Migration[5.0] 
    def change 
    add_column :items, :winner_id, :references, foreign_key: true 
    end 
end 

Gemfile: ':移行Herokuのは、すくいデシベル実行' の

結果

source 'https://rubygems.org' 

ruby '2.3.0' 

gem 'rails', '~> 5.0.0' 
gem 'pg' 
gem 'puma', '~> 3.0' 
gem 'sass-rails', '~> 5.0' 
gem 'uglifier', '>= 1.3.0' 
gem 'coffee-rails', '~> 4.2' 
gem 'jquery-rails' 
gem 'jbuilder', '~> 2.5' 
gem 'slim-rails' 
gem 'bootstrap-sass' 
gem 'devise' 
gem 'carrierwave' 
gem 'material_design_lite-sass' 
gem 'ransack' 
gem 'kaminari' 
gem 'rolify' 
gem 'business_process' 
gem 'decent_exposure', '3.0.0' 
gem 'friendly_id', '~> 5.1.0' 
gem 'simple_form' 
gem 'draper', github: 'audionerd/draper', branch: 'rails5' 
gem 'activemodel-serializers-xml' 
gem 'decent_decoration' 

group :development, :test do 
    gem 'pry-rails' 
    gem 'dotenv-rails' 
    gem 'ffaker' 
    gem 'better_errors' 
end 

group :development do 
    gem 'binding_of_caller' 
    gem 'sqlite3' 
    gem 'letter_opener' 
    gem 'web-console' 
    gem 'listen', '~> 3.0.5' 
    gem 'spring' 
    gem 'spring-watcher-listen', '~> 2.0.0' 
end 

gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 

関連「をdatabase.ymlを'部:

default: &default 
    pool: 5 
    timeout: 5000 

production: 
    <<: *default 
    database: ground_tree 
    adapter: postgresql 

はここでlink to app on github

で問題が発生しました:タイプBELONGS_TO(私はPGは、この名前をサポートしていないと仮定)ので、私はすべてを変えた:belongs_toのに:参照。

このエラーが発生しましたが、これを解決する方法がわかりません。

答えて

1

問題はあなたがadd_columnを間違って呼び出していることですが、SQLiteを使用すると問題が解決します。 fine manualから:

ADD_COLUMN(TABLE_NAME、COLUMN_NAME、タイプ、オプション= {})
table_namecolumn_nameという新しいtype列を追加します。
[...]

add_columnの三番目の引数は、列の型であると考えられるが、あなたは:referenceを渡しています。 PostgreSQLにはreference型がありませんので、文句を言います。 SQLiteにはreferenceタイプがありませんが、SQLiteは、textのエイリアスであると知らないタイプについては考慮しています。

あなたは右のタイプを使用する場合:

add_column :items, :winner_id, :integer, foreign_key: true 
# -----------------------------^^^^^^^^ 

を、あなたはより良い運を持っています。

詳細についてはActive Record Migrationsガイドをご覧ください。

関連する問題