Deleting all records in a database table

Deleting all records in a database table

Asked on January 12, 2019 in Ruby on Rails.
Add Comment


  • 3 Answer(s)

    It able to use delete_all is without SQL.

    Post.delete_all
    

    or

    Post.delete_all "person_id = 5 AND (category = 'Something' OR category = 'Else')"
    

     

    Answered on January 12, 2019.
    Add Comment

    Delete via SQL:

    
    Item.delete_all # accepts optional conditions
    

    And delete by calling each model’s destroy method,

    Item.destroy_all # accepts optional conditions
    

    Answered on January 12, 2019.
    Add Comment

    Completely empty the database and not just delete a model or models attached:

    
    rake db:purge
    

    test database.

    
    rake db:test:purge
    

    Answered on January 12, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.