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

データベースの削除方法(+カラムの追加と修正)

Last updated at Posted at 2020-04-15

新しいアプリを作ろうと思ったら昔作成した同じ名前のデータベースが残っていたときなど。

既にあるよ

% rails db:create
Database 'drill_app_development' already exists
Database 'drill_app_test' already exists

db:drop を使う

% bundle exec rake db:drop
Dropped database 'drill_app_development'
Dropped database 'drill_app_test'

カラム追加

マイグレーションファイルにカラム追記後

% rails db:migrate

カラム修正

% rails db:migrate:status
 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20200415025602  Create posts

上記コマンドでステータスを確認し

% rails db:rollback

updownにすればマイグレーションファイルを修正可能となる

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?