0
0

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.

migrationできない理由

Posted at
terminal
Caused by:
ActiveRecord::StatementInvalid: Mysql2::Error: Table 'tagtweet_development.tweets' doesn't exist
/Users/maedatakuo/projects/tagtweet/db/migrate/20210522115800_create_tweet_tag_relations.rb:3:in `change'
/Users/maedatakuo/projects/tagtweet/bin/rails:9:in `<top (required)>'
/Users/maedatakuo/projects/tagtweet/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'

原因:

ActiveRecord :: StatementInvalid:Mysql2 :: Error:テーブル 'tagtweet_development.tweets'は存在しません
・・・・・

どうやらテーブルを探しに行っているようです。

結論

外部キーばかりで作られたテービルを先に作ってしまっていました。
外部キーを含んだテーブルは後に作らないと連携の関係があるのでどうやら外部キー先のテーブルを参照するように作成されるようです。

マイグレーションの最初の番号を入れ替えると
以下のようにうまく作成できました。

terminal
== 20210522115800 CreateTags: migrating =======================================
-- create_table(:tags)
   -> 0.0824s
== 20210522115800 CreateTags: migrated (0.0827s) ==============================

== 20210522115853 CreateTweets: migrating =====================================
-- create_table(:tweets)
   -> 0.0908s
== 20210522115853 CreateTweets: migrated (0.0914s) ============================

== 20210522120027 CreateTweetTagRelations: migrating ==========================
-- create_table(:tweet_tag_relations)
   -> 0.0808s
== 20210522120027 CreateTweetTagRelations: migrated (0.0814s) =================
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?