删除 rails 中的模型(与“rails g 模型标题..."相反) [英] Removing a model in rails (reverse of "rails g model Title...")
本文介绍了删除 rails 中的模型(与“rails g 模型标题..."相反)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
rails g model Rating user_id:integer message:string value:integer
我怎样才能彻底删除这个模型?谢谢
How can I completely remove this model? Thanks
推荐答案
当您生成模型时,它会创建数据库迁移.如果在该模型上运行destroy",它将删除迁移文件,但不会删除数据库表.所以在运行之前
When you generate a model, it creates a database migration. If you run 'destroy' on that model, it will delete the migration file, but not the database table. So before run
bundle exec rails db:rollback
rails destroy model <model_name>
对于 5.0 及更高版本的 rails 版本使用 rake
而不是 rails
For rails versions before 5.0 and higher use rake
instead of rails
bundle exec rake db:rollback
rails destroy model <model_name>
这篇关于删除 rails 中的模型(与“rails g 模型标题..."相反)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文