gpt4 book ai didi

database - 在 Rails 中销毁/删除数据库

转载 作者:IT王子 更新时间:2023-10-29 06:17:56 26 4
gpt4 key购买 nike

是否可以从现有应用程序中完全删除数据库和所有迁移记录等,以便我可以从头开始重新设计数据库?

最佳答案

通过发出 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

关于database - 在 Rails 中销毁/删除数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17649686/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com