回答

39

通過發行rake -T您有以下數據庫任務:

rake db:create   # Create the database from DATABASE_URL or config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config) 
rake db:drop   # Drops the database using DATABASE_URL or the current Rails.env (use db:drop:all to drop all databases) 
rake db:fixtures:load # Load fixtures into the current environment's database 
rake db:migrate   # Migrate the database (options: VERSION=x, VERBOSE=false) 
rake db:migrate:status # Display status of migrations 
rake db:rollback  # Rolls the schema back to the previous version (specify steps w/ STEP=n) 
rake db:schema:dump  # Create a db/schema.rb file that can be portably used against any DB supported by AR 
rake db:schema:load  # Load a schema.rb file into the database 
rake db:seed   # Load the seed data from db/seeds.rb 
rake db:setup   # Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the db first) 
rake db:structure:dump # Dump the database structure to db/structure.sql 
rake db:version   # Retrieves the current schema version number 

因此,要發佈bundle exec rake db:drop:all,並且如果要刪除所有遷移,並且假設你只想刪除遷移,刪除它們並寫入新的遷移。

如果您也想更換模型,請使用rails d model

4

這將擺脫分貝:

rake db:drop 

併爲每個遷移,你必須:

rails d migration migration_name 
+0

非常感謝。還有什麼我應該清理? (我剛開始學習Rails)。 – fearofawhackplanet

0

是的,它可能會刪除數據庫和遷移。

rake db:drop 
rake db:rollback 
rails d migration 'migration name' 
rake db:create 
rake db:migrate 
rake db:seed 
rake db:test:prepare