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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:16:59+00:00 2026-06-07T21:16:59+00:00

Migration fails in production, but ran as expected in development. … # everything to

  • 0

Migration fails in production, but ran as expected in development.

...                                                               # everything to
20120709174326_add_subject_to_campaigns.rb                        # here runs fine.
20120711001125_set_default_value_for_publishable_in_newsletter.rb # <- this fails.
20120711010818_set_default_value_for_publishable_in_contents.rb
20120711010855_set_default_value_for_published_in_editions.rb
20120711191427_add_newsletter_date_to_newsletters.rb
20120711194230_rename_cm_campaign_sent_at_in_campaigns.rb

The migration error looks like this:

-bash> heroku run rake db:migrate --remote staging
Running rake db:migrate attached to terminal... up, run.1
==  SetDefaultValueForPublishableInNewsletter: migrating ======================
-- change_column(:newsletters, :publishable, :boolean, {:default=>false})
   -> 0.1554s
rake aborted!
An error has occurred, this and all later migrations canceled:

undefined method `newsletter_date' for #<Newsletter:0x00000005961bd0>

The thing is, newsletter_date is not added till later, so why is it failing / mentioning it so soon? It ran perfectly fine in development.

  • 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-07T21:17:01+00:00Added an answer on June 7, 2026 at 9:17 pm

    It turns out that the failing migration (20120711001125_set_default_value_for_publishable_in_newsletter.rb) …

    def up
      change_column :newsletters, :publishable, :boolean, default: false
      Newsletter.scoped.where('publishable is NULL').each do |n|
        n.publishable = false
        n.save
      end
    end
    

    … uses the model Newsletter, and runs validations before saving (specifically, the presence validation on newsletter_date) …

    validates :newsletter_date, presence: true
    

    … but newsletter_date does not exist yet, because it (the newsletter_date column) is not added till later (20120711191427_add_newsletter_date_to_newsletters.rb — the second-last migration in the list above):

    class AddNewsletterDateToNewsletters < ActiveRecord::Migration
      def change
        add_column :newsletters, :newsletter_date, :date
      end
    end
    

    The solution is: (1) in development, rollback the migrations to the one before the failing one; (2) rename the migration that adds the column, changing its timestamp to just prior to the failing migration; (3) run the migrations; (4) update git; (5) push to Heroku; (6) in production, run the migrations; (7) restart the Heroku processes.

    bundle exec rake db:rollback # five times in this case
    mv db/migrate/20120711191427_add_newsletter_date_to_newsletters.rb db/migrate/20120711001025_add_newsletter_date_to_newsletters.rb
    bundle exec rake db:migrate
    git add db/migrate/20120711001025_add_newsletter_date_to_newsletters.rb
    git rm db/migrate/20120711191427_add_newsletter_date_to_newsletters.rb
    git commit -m "changed migration timestamp to fix migration order issue"
    git push staging master
    heroku run rake db:migrate --remote staging
    heroku restart --remote staging
    

    The reason it worked in development is because at the time the migration that set the default value for the publishable column in the newsletters table ran, the newsletter_date column and model validation did not yet exist, so it was not a problem. By the time it all went out to production, the more recent code brought the newsletter_date method and related validation into existence, but since migrations run on existing code in order of timestamps, newer code may exist than the database is prepared for.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On my development machine I can login fine, but once on production, authentication fails
I want do run migration on my app that I have on heroku but
Using Grails database-migration I have a table in production defined like so: +--------------+------------+------+-----+---------+----------------+ |
I need to do migration date->timestamp with timezone similar to described here: Migrating Oracle
Here is the scenario production/staging code is on version X Version X of code
Alrite.. so.. here's a situation: I am responsible for architect-ing the migration of an
I'm migrating an older .net application to .net 4, this migration has to be
I've search everywhere for a pointer to this, but can't find one. Basically, I
I'm testing my Rails application with RSpec, but then I ran into a problem.
I consider to use Flyway with postgresql. When a migration fails do I need

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.