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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:40:27+00:00 2026-05-28T13:40:27+00:00

On Amazon’s EC2 using Ubuntu, when I execute rake db:migrate as: bundle exec rake

  • 0

On Amazon’s EC2 using Ubuntu, when I execute rake db:migrate as:

bundle exec rake db:migrate RAILS_ENV="production" --trace

I get the error ActiveRecord::ConnectionNotEstablished as shown below

 ** Invoke db:migrate (first_time)
 ** Invoke environment (first_time)
 ** Execute environment
 ** Execute db:migrate
 rake aborted!
 ActiveRecord::ConnectionNotEstablished
 /usr/local/rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:316:in `retrieve_connection'

I can login to mysql with the username and password in my config/database.yml file
and the database is there. So mysql is running, and that is not the problem.

My config/database.yml file looks like:

 production:
   adapter: mysql2
   encoding: utf8
   reconnect: false
   database: app_production
   pool: 5
   username: root
   password: password
   host: localhost
   socket: /run/mysqld/mysqld.sock

Here are my gems from gem list:

 abstract (1.0.0)
 actionmailer (3.0.3)
 actionpack (3.0.3)
 activemodel (3.0.3)
 activerecord (3.0.3)
 activeresource (3.0.3)
 activesupport (3.0.3)
 arel (2.0.10)
 builder (2.1.2)
 bundler (1.0.10 ruby)
 cgi_multipart_eof_fix (2.5.0)
 daemons (1.0.10)
 erubis (2.6.6)
 eventmachine (0.12.10)
 fastthread (1.0.7)
 gem_plugin (0.2.3)
 i18n (0.6.0)
 mail (2.2.19)
 mime-types (1.17.2)
 mongrel (1.2.0.pre2)
 mysql2 (0.2.7)
 polyglot (0.3.3)
 rack (1.2.5)
 rack-mount (0.6.14)
 rack-test (0.5.7)
 rails (3.0.3)
 railties (3.0.3)
 rake (0.9.2.2)
 rmagick (2.13.1)
 thin (1.2.7)
 thor (0.14.6)
 treetop (1.4.10)
 tzinfo (0.3.31)
 xmpp4r (0.5)

The error in connection_pool.rb is happening at the same place as described in this post whose answer says that a connection needs to be established on ActiveRecord::Base. The code is failing in connection_pool.rb because it is getting sent klass = ActiveRecord::Base which doesn’t have a connection. So I tried creating a model my_connection_base.rb that looks like the following

 require 'active_record'

 class MyConnectionBase < ActiveRecord::Base

      MyConnectionBase.establish_connection(
        :adapter => "mysql2",
        :host => "localhost",
        :username => "<your database username>",
        :password => "<your database password>",
        :database => File.dirname(__FILE__) + "app_production"
      )
   self.abstract_class = true
 end

And then all of my models inherit MyConnectionBase as in role.rb below:

require 'my_connection_base'

class Role < MyConnectionBase
  has_and_belongs_to_many :users
end

But I still get ActiveRecord::ConnectionNotEstablished when I try to run a migration. Is there something else I need to do with Rails 3 to ensure that the connection is made to mysql before performing the migration?

  • 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-28T13:40:28+00:00Added an answer on May 28, 2026 at 1:40 pm

    I was able to get the migrations to work by adding db:create to the rake command line as shown below:

     bundle exec rake db:create db:migrate RAILS_ENV="production" 
    

    I don’t know why db:create is needed now. One thing I didn’t mention is that these migrations were transferred from a Rails 2 application to a Rails 3 application. I’m still having trouble creating pages in the migration, as shown below in the Page.create section that I commented out:

    20101014205123_create_pages.rb

     class CreatePages < ActiveRecord::Migration
       def self.up
         create_table :pages do |t|
           t.column :title, :string
           t.column :permalink, :string
           t.column :body, :text
           t.column :created_at, :datetime
           t.column :updated_at, :datetime
           t.timestamps
         end
    
     #   Page.create(:title => "Home",
     #               :permalink => "welcome-page",
     #               :body => "Welcome to Home")
    
       end
    
       def self.down
         drop_table :pages
       end
     end
    

    It also looks like the initial data creation can be done in db/seeds.rb which is where I transfered the Page.create code. I am still trying to get that to work using:

     bundle exec rake db:create db:seed RAILS_ENV="production" --trace
    

    and I’m getting the error:

     uninitialized constant Page
    

    I was able to fix this error by requiring the model in db/seeds.rb as shown below:

    require File.expand_path('../../app/models/page', __FILE__)
    
    Page.create(:title => "Home",
                :permalink => "welcome-page",
                :body => "Welcome to Home")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Amazon's own client libraries (or alternatives ), you can get listings of available
I'm considering using Amazon's EC2 with a windows instance & SQL. I've seen some
I'm using Amazon EC2 with a Fedora 8 Core AMI. I have an EBS
I am using the Amazon and eBay API via PHP5 and Curl to get
I am using the Amazon MWS API to get the sales report for my
I'm using the amazon-ecs gem to get product details from Amazon, using the itemlookup
I am using amazon EC2 and I'm in the process of creating a CMS.
Amazon Mechanical Turk is a mass-micro outsourcing API, where you can get lots's of
Amazon offers two instance types on EC2: 1) On-Demand and 2) Reserved. After reading
I try to use amazon API using PHP. If I use print_r($parsed_xml->Items->Item->ItemAttributes) it show

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.