質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

Q&A

1回答

1330閲覧

heroku run rake db:migrate でエラー

dxo

総合スコア16

Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

0グッド

2クリップ

投稿2020/01/10 06:40

編集2022/01/12 10:55

heroku run rake db:migrateをすると、以下のようなエラーが発生します。
カラムdelivery_dateを一度消して、heroku run rake db:resetをし、再度heroku run rake db:migrateをしたりしたのですが、以下のエラー文が直りません。

どのようにすれば良いでしょうか。
ご教授よろしくお願い致します。

delivery_dateのデータの型は、dateです。
herokuには、time zoneを東京で追加しております。
また、config/application.rbへも、config.time_zone = 'Tokyo'を追加しております。

rake aborted! StandardError: An error has occurred, this and all later migrations canceled: PG::DatatypeMismatch: ERROR: column "delivery_date" cannot be cast automatically to type timestamp without time zone HINT: You might need to specify "USING delivery_date::timestamp without time zone". /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:92:in `exec' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:92:in `block (2 levels) in execute' /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.2.1/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads' /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.2.1/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares' /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.2.1/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:91:in `block in execute' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_adapter.rb:718:in `block (2 levels) in log' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_adapter.rb:717:in `block in log' /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.2.1/lib/active_support/notifications/instrumenter.rb:24:in `instrument' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_adapter.rb:708:in `log' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:90:in `execute' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/postgresql/schema_statements.rb:402:in `change_column' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:890:in `block in method_missing' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:858:in `block in say_with_time' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:858:in `say_with_time' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:879:in `method_missing' /app/db/migrate/20200107111610_change_datatype_delivery_date_of_patterns.rb:3:in `change' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:828:in `exec_migration' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:812:in `block (2 levels) in migrate' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:811:in `block in migrate' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:473:in `with_connection' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:810:in `migrate' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1001:in `migrate' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1311:in `block in execute_migration_in_transaction' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1362:in `block in ddl_transaction' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:281:in `block in transaction' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract/transaction.rb:280:in `block in within_new_transaction' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract/transaction.rb:278:in `within_new_transaction' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:281:in `transaction' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/transactions.rb:212:in `transaction' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1362:in `ddl_transaction' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1310:in `execute_migration_in_transaction' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1282:in `block in migrate_without_lock' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1281:in `each' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1281:in `migrate_without_lock' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1229:in `block in migrate' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1382:in `with_advisory_lock' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1229:in `migrate' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1061:in `up' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1036:in `migrate' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/tasks/database_tasks.rb:238:in `migrate' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/railties/databases.rake:86:in `block (3 levels) in <main>' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/railties/databases.rake:84:in `each' /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/railties/databases.rake:84:in `block (2 levels) in <main>' /app/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/exe/rake:27:in `<top (required)>' /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.2/lib/bundler/cli/exec.rb:74:in `load' /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.2/lib/bundler/cli/exec.rb:74:in `kernel_load' /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.2/lib/bundler/cli/exec.rb:28:in `run' /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.2/lib/bundler/cli.rb:465:in `exec' /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.2/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run' /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.2/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command' /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.2/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch' /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.2/lib/bundler/cli.rb:27:in `dispatch' /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.2/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start' /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.2/lib/bundler/cli.rb:18:in `start' /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.2/exe/bundle:30:in `block in <top (required)>' /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.2/lib/bundler/friendly_errors.rb:124:in `with_friendly_errors' /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.2/exe/bundle:22:in `<top (required)>' /app/bin/bundle:104:in `load' /app/bin/bundle:104:in `<main>'

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

私は似たような事象が起きたことがあります。

その時の解決方法は、
herokuより現在の途中経過のリポジトリを削除して、
もう一度環境構築したらすんなりいきました。

migrateファイルを直して再試行したのになぜかエラーが出てしまうという現象だったのですが、
その際は、herokuに残留ファイルがありそいつが悪さしていてうまくmigrateできなかったのでは?という仮説で行った対処でした。

どうしても直らなければイチからやるのが良いです。

投稿2020/01/10 06:47

kaori_oka

総合スコア176

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

dxo

2020/01/10 07:05 編集

ご回答いただきありがとうございます。 ただ今、リポジトリを削除して、もう一度構築し直したのですが、同じエラーが発生致しました。 PG::DatatypeMismatch: ERROR: column "delivery_date" cannot be cast automatically to type timestamp without time zone HINT: You might need to specify "USING delivery_date::timestamp without time zone".
dxo

2020/01/10 07:07

time zoneの設定の問題ではなさそうなんですよね
kaori_oka

2020/01/10 07:56

timezone系でコケたことないので、仮説になっちゃいますが、 migrateファイルって作ったら基本消さないでやってますが、 その途中経過のtableづくりに問題があるのでは? DBなのでymlファイルになにかをしなければいけないのか? などが気がかりです。 いろいろ検索してみたのですが、これ!っていうのがわからないかったので、ただのコメントですが...
kaori_oka

2020/01/10 08:01

herokuのDBは「Postgresql」、自身の環境のDBが「MySQL」となると、 その違いなどでコケる場合があるそうです。 引き続き調べてします。ちゃんとした回答じゃなくてすみません。
dxo

2020/01/10 08:45

ご返答誠にありがとうございます。お手数おかけして申し訳ございません。 ログを見ていますと、 ALTER TABLE "patterns" ALTER COLUMN "delivery_date" TYPE timestamp と書いてあり、カラムの型は、「date」になっているのですが、こちらに問題があるとかでしょうかね、、。
kaori_oka

2020/01/10 08:51

確実性のある返答ができずもうしわけないですが、 特にこだわりがないのなら、 私だったらダメもとで「date」=>「timestamp」としてデータテーブル群の再構築してmigrateできるか試してみちゃいますね。
退会済みユーザー

退会済みユーザー

2020/01/10 10:04

というか、開発とサーバーのミドルウェアは合わせましょうといいたいところ
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問