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

  • SEARCH
  • Home
  • 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 5837839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:24:14+00:00 2026-05-22T11:24:14+00:00

This is probably in another question, but I cannot find it. I am a

  • 0

This is probably in another question, but I cannot find it.

I am a relative noobie to Rails. I am trying to add a new column to a table that already has data in it. This column is not going to allow nulls. What is the easiest way to update all the existing records to have a value in this new column? I know it is probably in the up block of my migration, but I don’t know what the syntax would be.

def self.up
  change_table :reminders do |t|
    t.boolean :active
  end
  #model name is Reminder - how to update data with a value?
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-22T11:24:15+00:00Added an answer on May 22, 2026 at 11:24 am

    What you can do is add the column, update all records in the table with the desired value, then change it to not allow nulls.

    def self.up
      add_column :reminders, :active, :boolean, :default => true
      Reminder.update_all( "active = ?", true )
      change_column :reminders, :active, :boolean, :default => true, :null => :false
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yes, this is probably yet another greatest-n-per-group question... But I've tried at least a
This is probably more of a JavaScript question but I'd like to pass another
This is probably a very newbie question but what I'm trying to do is
This is probably a silly question but i haven't been able to find the
Okay, this is (probably) a very simple question, but I am afraid I know
This is probably a really stupid question but I can't figure this out. I
This is probably a dumb question but I'm just learning. If I have a
This is probably another easy Haskell question. If I have some nested data types,
I know this is probably the canonical It depends... question but I'd appreciate any
This is probably a stupid question but, I cant for the love of god

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.