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 9250627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:29:16+00:00 2026-06-18T10:29:16+00:00

I run: rails generate migration AddHidemsgColumnToPublishers hide_msg:boolean and the next file was created: class

  • 0

I run:

rails generate migration AddHidemsgColumnToPublishers hide_msg:boolean

and the next file was created:

class AddHidemsgColumnToPublishers < ActiveRecord::Migration
  def change
    add_column :publishers, :hide_msg, :boolean
  end
end

I want to set a default value into hide_msg by false.

so I tried:

rails generate migration add_default_value_to_hide_msg

class AddDefaultValueToHideMsg < ActiveRecord::Migration
  def up
    change_column :publishers, :hide_msg, :boolean, :default => false
  end

  def down
    change_column :publishers, :hide_msg, :boolean, :default => nil
  end
end

but I got errors:

rake db:migrate
==  AddHidemsgColumnToPublishers: migrating ===================================
-- add_column(:publishers, :hide_msg, :boolean, {:default=>false})
rake aborted!
An error has occurred, this and all later migrations canceled:

PG::Error: ERROR:  column "hide_msg" of relation "publishers" already exists
: ALTER TABLE "publishers" ADD COLUMN "hide_msg" boolean DEFAULT 'f'
  • 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-06-18T10:29:17+00:00Added an answer on June 18, 2026 at 10:29 am

    Just a suggestion…. do not set the default value in the database, as you might face some problems if you want to change it latter on.

    I think it is better if you set it in your model.

    before_save :set_default_high_msg
    def set_default_high_msg
      self.high_msg ||= false
    end
    

    or even in your controller:

     def new
       @publisher = Publisher.new
       @publisher.high_msg ||= false
     ...
     end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I run: rails generate migration AddShowmsgColumnToPublishers show_msg:boolean rake db:migrate but now, I want to
I'm having this table class CreateEvents < ActiveRecord::Migration def self.up create_table :events do |t|
I'd like to run the rails generate script and create a model that belongs
In Rails, I want to run the js.erb file associated with an action on
Im creating a simple Rails 2.3.8 gem and need a migration file inside it.
When I run this: rails generate controller hello index it no doubt generates hello
If I run rails generate controller ControllerName I get an empty controller? I can
Hi I downloaded the plugin from http://github.com/techweenie/restful-authentication.git Then I run rails generate plugin authenticated
I created a model using: rails generate model SavingsItem I then ran rake db:migrate
My Rails app suddenly stopped to work when i try to run migration. For

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.