0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

bin/rails db:migrateしようとしたらMysql2::Error: Table '*****' doesn't existが出る

Last updated at Posted at 2020-02-27
1 / 3

##経緯

bin/rails g model image

bin/rials g model product

によって作られたマイグレーションファイル
20200227092210_create_images.rb
20200227092647_create_products.rbを,

20200227092210_create_images.rb
(中略)
      t.references :product, foreign_key: true
(中略)

と書いて, bin/rails db:migrate を実行

##起きたエラ〜

(中略)
rails aborted!
StandardError: An error has occurred, all later migrations canceled:

Mysql2::Error: Table 'プロジェクト名_development.products' doesn't exist: SHOW FULL FIELDS FROM `products`
(中略)

というエラーが発生した。

##解決策
どうやら、
referencesされるマイグレーションファイル
の方が先にmigrateされるべきなようで、


20200227092647_create_products.rbを、
 →2020022709 2209_create_products.rb
  (20200227092210_create_images.rb)
にすると、images.rbよりも早くmigrateされた!!

###参照したwebページ
teratail:rails db:migrateができません(おそらくmysqlのカラムがマッチしていない)

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?