1
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 5 years have passed since last update.

db:migrateでalready existだった時の話

Posted at

modelが気に入らなくて作り直そうとした

そういうこと、ありません?
開発中に「あれ?この変数忘れてたわ」とmodelを作り直したいなーって思って、rails destroy => rais generate modelしたんですよ。
んでdb:migrateしようと思ったらご覧のありさま。

ec2-user:~/environment/circle-list (master) $ rails db:migrate
== 20190216164559 CreateCircles: migrating ====================================
-- create_table(:circles)
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: table "circles" already exists: CREATE TABLE "circles" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar, "space" varchar, "memo" varchar, "url" varchar, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
  (以下略)

SQLite上に作りたいテーブルは既にいるよ!と怒られました。
うん知ってる。ゴリ押しでどうにかしたいんだよこっちは。

つよくてにゅーげーむ

テーブルの中身をふっとばしていいなら「db:migrate」の後ろに「reset」をつけよう

$ rails db:migrate:reset
Dropped database 'db/development.sqlite3'
Database 'db/test.sqlite3' does not exist
Created database 'db/development.sqlite3'
Created database 'db/test.sqlite3'
== 20190216164559 CreateCircles: migrating ====================================
-- create_table(:circles)
   -> 0.0020s
== 20190216164559 CreateCircles: migrated (0.0027s) ===========================
1
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
1
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?