概要
いつもお世話になります。
この度、 RailsTutorial 14章を進行中にローカルのSQliteのDBにてrails db:
関連で躓いてしまいました。
エラーメッセージは以下の通りです。
エラーメッセージ
SQLite3::SQLException: table "microposts" already exists /Users/nasa/Gdrive_r75rid/local_document/Ruby/environment/tumatter_app/vendor/bundle/ruby/2.3.0/gems/sqlite3-1.3.13/lib/sqlite3/database.rb:91:in `initialize'
試したこと
ここで、"microposts"テーブルが存在しているのにrails db:migrate
で更に"microposts"をCreateしようとしているので怒られているのかと思い、stack overflowのこちらの記事を参考にmicopostsのdrop migrationを生成しrails db:migrate
を試みたのですが、やはり同じエラー内容で怒られてしまいます。
思い当たる節
- デフォルトのDB指定はdevelopです。
ただmigrateをした際に、rais db:migrate RAILS_ENV=test
をしてね!とたまに怒られていたので実行していました。このDBの環境指定なのか
- 14章に入った直後にユーザーのfollow関係を定義するmigrateをしたのですが、DBがおかしいと気づき、ブランチの変更内容を全てcheckoutしたのが原因なのか
関連ファイル
- db/migrate/20180829203429_create_microposts.rb
class CreateMicroposts < ActiveRecord::Migration[5.1] def change create_table :microposts do |t| t.text :content t.references :user, foreign_key: true t.timestamps end # 1つの配列に2つのキーを同時に扱う複合キーインデックスを作成 add_index :microposts, [:user_id, :created_at] end end
- db/migrate/20180901051251_add_picture_to_microposts.rb
class AddPictureToMicroposts < ActiveRecord::Migration[5.1] def change add_column :microposts, :picture, :string end end
- db/migrate/20180904023036_drop_microposts.rb
class DropMicroposts < ActiveRecord::Migration[5.1] def up drop_table :microposts end end
何かお気づきの箇所やご指摘など御座いましたらよろしくお願いします????????

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。