環境は
Ruby:3.0.2
Rails:7.0.3
Cloud9
です
下記のようなマイグレーションファイルをrails db:migrateで実行するとエラーが出ます
名前は重複してないはずなんですけどこれはなぜなのでしょうか?
またどうすればこの「tweet_id」のまま使えますでしょうか?
Ruby
1class CreateComments < ActiveRecord::Migration[7.0] 2 def change 3 create_table :comments do |t| 4 5 6 t.string :image 7 t.integer :user_id 8 t.integer :tweet_id 9 t.text :body 10 t.references :tweet, null: false, foreign_key: true 11 t.timestamps 12 end 13 end 14end 15
エラー内容
== 20220620234356 CreateComments: migrating ===================================
-- create_table(:comments)
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:
you can't define an already defined column 'tweet_id'.
/home/ubuntu/environment/jisya_app/db/migrate/20220620234356_create_comments.rb:8:in block in change' /home/ubuntu/environment/jisya_app/db/migrate/20220620234356_create_comments.rb:3:in
change'
Caused by:
ArgumentError: you can't define an already defined column 'tweet_id'.
/home/ubuntu/environment/jisya_app/db/migrate/20220620234356_create_comments.rb:8:in block in change' /home/ubuntu/environment/jisya_app/db/migrate/20220620234356_create_comments.rb:3:in
change'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

回答1件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
また依頼した内容が修正された場合は、修正依頼を取り消すようにしましょう。
2022/06/21 01:26