Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete model and migration file rails 4

I was attempting to add a tagging model to my rails blog. But I accidentally generated a "Tags.rb" model as opposed to "Tag.rb", after reading the guide I realized that making "tag" plural was a mistake when it comes to model. I rolled back the migration using

  rake db:rollback 

and then

  rails destroy model Tags.rb 

and this was what i got back

  invoke  active_record
  remove    /home/migration/templates/create_table_migration.rb
  remove    app/models/tags.rb.rb
  invoke    test_unit
  remove      test/models/tags.rb_test.rb
  remove      test/fixtures/tags.rbs.yml

When I come back to the model folder though its still there. Please help :)

like image 227
nadia Avatar asked Feb 12 '14 01:02

nadia


People also ask

Can I delete a migration file Rails?

No, since Rails would not know how to delete it. It needs to call the self. down method defined on your migration to "downgrade" your database.

How do I delete a model Rails?

Rails delete operation using destroy method By using destroy, you can delete the record from rails as well as its other existing dependencies. So in the context of our rails application, if we delete a book record using the destroy function, the authors associated with the book will also be deleted.

How do I delete a migration?

To delete a migration created using Mover, do the following: Click Migration actions. From the dropdown menu, select Delete migration.

How do I revert migration in Rails?

To check for status, run rails db:migrate:status . Then you'll have a good view of the migrations you want to remove. Then, run rails db:rollback to revert the changes one by one. After doing so, you can check the status again to be fully confident.


4 Answers

Just give

rails destroy model Tag
like image 135
prash Avatar answered Oct 12 '22 23:10

prash


Try using tags plural without the additional .rb, like

rails destroy model Tags

Hope this helps

like image 1
strivedi183 Avatar answered Oct 12 '22 22:10

strivedi183


You can manually delete the files, or just manually remove the "s"s.

like image 1
Josh Avatar answered Oct 13 '22 00:10

Josh


try this

bundle exec rake db:rollback

and then delete your model as

rails destroy model <model_name>

now totaly deleted.

like image 1
Antony Mithun Avatar answered Oct 12 '22 23:10

Antony Mithun