Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6752767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:05:00+00:00 2026-05-26T13:05:00+00:00

How should I remove sample data in the self.down method(s) for both the migrations

  • 0

How should I remove sample data in the self.down method(s) for both the migrations listed below

class FooSampleData < ActiveRecord:Migration

  def self.up
     Foo.create(:bar => 1)
     Foo.create(:bar => 2)
     Foo.create(:bar => 3)
  end

  def self.down
  end
end

class FooSampleDataV2 < ActiveRecord:Migration

  def self.up
     Foo.create(:bar => 4)
     Foo.create(:bar => 5)
     Foo.create(:bar => 6)
  end

  def self.down
  end
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:05:00+00:00Added an answer on May 26, 2026 at 1:05 pm

    If you are creating your database table at the same time, then destroying table will destroy data.

    If :bar is unique, you may find by bar and destroy the object.

    # up
    Foo.create([{:bar => 1},{:bar => 2},{:bar => 3})
    
    # down
    Foo.where(:bar => [1,2,3]).each { |foo| foo.destroy }
    

    Edited

    I don’t know your scenario. Seed usually is used for starting up an application. If you are in an incremental development (with deploys) usually initial data is included when we create our model, and not in a exclusive migration as you show in your example.

    If you really need to do it in a exclusive migration, your drop work will be proportional do your create work.

    In my projects I avoid adding data in migrations.

    Some useful links:

    • Rails Guides: migrations
    • Rails Casts: seed data
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code, that should remove the access of users from a
Q1 Book suggests that before we register new SqlProfileProvider , we should remove any
I am migrating an application from .NET 1.1 to .NET 2.0. Should I remove
Say,should keep the space between letters(a-z,case insensitive) and remove the space between non-letters?
The following code should find the appropriate project tag and remove it from the
This would have been a lot easier if not for certain situations. Sample data:
I have the following domain object: public class Data { public virtual int ID
How can i remove $_SERVER['DOCUMENT_ROOT'] from a string like this /home/bla/test/pic/photo.jpg the result should
Should I start with Django or JavaScript?
Should the folders in a solution match the namespace? In one of my teams

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.