Purge or recreate a Ruby on Rails database

前端 未结 19 1289
清酒与你
清酒与你 2020-11-28 17:01

I have a dev Ruby on Rails database full of data. I want to delete everything and rebuild the database. I\'m thinking of using something like:

rake db:recrea         


        
19条回答
  •  时光说笑
    2020-11-28 17:29

    3 options, same result:

    1. All steps:

      $ rake db:drop           # deletes the database for the current env
      $ rake db:create         # creates the database for the current env
      $ rake db:schema:load    # loads the schema already generated from schema.rb / erases data
      $ rake db:seed           # seed with initial data
    

    2. Reset:

      $ rake db:reset          # drop / schema:load / seed
    

    3. Migrate:reset:

      $ rake db:migrate:reset  # drop / create / migrate
      $ rake db:seed
    

    Notes:

    • If schema:load is used is faster than doing all migrations, but same result.
    • All data will be lost.
    • You can run multiple rakes in one line.
    • Works with rails 3.

提交回复
热议问题