I deployed my first rails app to a production server a few days ago. Since then, I've been working on some fixes on my development machine and I pushed those over to the production server via git. I touched the restart.txt file and then restarted Apache, and now I'm getting a Passenger error that I think is related to gems and bundle.
When I first started development I ran into an issue (here) and I removed the .bundle directory. I then ran bundle install again on my development machine, and all seemed well while I fixed some bugs.
Now I'm ready to redeploy the next version of the app, and after these errors, I checked and noticed that I don't even have a .bundle directory anymore. bundle install doesn't create a new one. I assume nothing's going to work without that? Should I just manually create the requisite files or is there a command to regenerate those?
EDIT to add error: syntax error on line 3, col 2: adapter:sqlite3'
database.yml:
# SQLite version 3.x
gem install sqlite3
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
Is the gem install sqlite3 in your listing of database.yml actually present in that file? If that is the case than that is the cause of the error as it is invalid YAML. Also, the statement doesn't make sense here, as the file isn't interpreted by neither bundler nor ruby.
At best, just remove (or comment) that statement there and try gain.
Edit: Generally, whitespace (especially leading whitespace) is rather important in YAML. Don't mix spaces and tabs here. It would confuse the parser. Also there need to be a space between the key and the value in a hash like so
key: value
# ^ this space is important!
Please refer to YAML's Wikipedia article for more info about YAML syntax.
#Paul, can you try updating your gemfile as follows
group :production do
# gem 'mysql2' # disabled to debug Paul's issue.
gem 'sqlite3-ruby', :require => 'sqlite3'
end
group :development do
gem 'sqlite3-ruby', :require => 'sqlite3'
end
Let me know how this pans out.
Related
I'm trying to use rails 4.2.6 to develop an app. I'm trying to use postgres for database. Server starts fine but when I try loading a page it throws this "No connection pool for ActiveRecord::Base" error.
What could it be?
EDIT
The pg gem wasn't working properly. I had to comment it before starting the server and then uncomment it from my GemFile afterwards. I realized that I was using Ruby 2.3 instead of Ruby 2.0 (as intended). I removed ruby 2.3 and set up everything under ruby 2.0 environment. It's now working properly.
I had read somewhere that there were some issues with the 'pg' gem in newer Rails releases, requiring people to use 'gem install pg --pre' instead for installing the gem. I tried that, but then my app was requiring the 'pg' gem in my GemFile and, well, the problem stated above showed up again.
This is how my database.yml file ended up:
default: &default
adapter: postgresql
encoding: unicode
host: localhost
username: -------
password: -------
pool: 5
development:
<<: *default
database: myDbName
If you are experiencing this error from a rake task, chances are you are not running the :environment task before your task.
Changing:
task :task_name do
end
to:
task task_name: :environment do
end
Should fix the issue.
This issue arises when the server cannot find the corresponding database it depends on to pull data from.
I had same issue from my end, I updated my version of Sqlite3, and it was higher than the version that the current Puma Server version supports.
I simply had to uninstall the Sqlite3 version, and then install the version supported by the current version of Puma Server.
gem uninstall sqlite3
This will uninstall the updated version of Sqlite3, and then you run the code below stating the version supported by your current server.
gem install sqlite3
Or you can as well open your Gemfile, and then include the version for the database that you are using
gem 'sqlite3', '~> 1.3.6'
N/B: The sqlite3 version is the most current version as at the time of writing this answer
And then run
bundle update
to install the version of the database that you specified.
That's all.
I hope this helps.
For PostgreSQL your database.yml file should look something like that:
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: 5
development:
<<: *default
database: your_db_name
Also make sure that you have the gem installed: in your Gemfile:
gem 'pg'
Finally, restart your server.
Hope that helps
Edit: I almost forgot, make sure you have your PostgresSQL running, check this link for download and setup.
Check the database.yml if all settings are ok. If its the first time and you didn't create the database yet use this command to create the database
rake db:create
If the database already exists try reset the db migrations,
rake db:migrate:reset
Hope it'll solve the problem. Go to rails console and try something to check if its working or not.
I had to simply restart the server for the warning to go away.
I've encountered the same problem when I try to access the Model before creating the DataBase.
Make sure you run rake db:migrate at least once.
If you already run migration then check the Database as mentioned in previous answers.
In my case, the config/database.yml was taking variables from the environment:
# ...
test:
<<: *default
database: <%= ENV.fetch("DB_NAME") %>_test
username: <%= ENV.fetch("DB_USER") %>
password: <%= ENV.fetch("DB_PASS") %>
# ...
The error was coming when the new terminal window where I was running the bundle exec rails spec did not have those variables initialized.
Doing,
$ export DB_NAME=mydb
$ export DB_USER=myuser
$ export DB_PASS=mypass
$ bundle exec rails spec
fixed the issue.
I had to restart the server, and make sure you entered username and password. Create development and test databases
when you are running rails db:migrate in data base rows will be created according to your migration files. you can see schema for further info.
Rails 5
New app
Using Postgresql for both test and development
Specs run, so Rails can connect to Postgresql
But when I started the web app, I got "No connection pool with id primary found."
Ran 'bin/rails db:migrate:reset' and restarted the app. It worked. No idea why.
database.yml:
development:
adapter: postgresql
encoding: unicode
database: rails5_development
pool: 5
username: foo
password: bar
host: localhost
port: 5432
test:
adapter: postgresql
encoding: unicode
database: rails5_test
pool: 5
username: foo
password: bar
host: localhost
port: 5432
I've just installed rbenv, ruby 2.2.3 and rails 4.2.4 for the first time on this machine. I've started my rails application with no change to any of the code, just the default generated documents from using rails new ., I then started the server with rails server.
When hitting http://localhost:3000 I'm getting the following error:
"Specified 'postgresql' for database adapter, but the gem is not loaded. Add gem 'pg' to your Gemfile (and ensure its version is at the minimum required by ActiveRecord)."
I've got postgres installed from a previous project with Node, but my database.yml still reads as you'd expect from a new application:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3
I don't really want to use Postgres at the moment, I'm just starting out and I'd rather keep things simple with SQLite3 for a bit. Does anyone know what may be going on and what I could do to get it using SQLite3 so that this error stops?
There is another solution, for those who actually need to keep the DATABASE_URL environment variable without affecting Rails (like me). You can use a url sub key:
development:
<<: *default
url: sqlite3:db/development.sqlite3
This is documented here.
The problem is that when you start the server it is looking for environment variable DATABASE_URL which is probably set to postgres and this takes precedence over the database.yml file. You can delete the environment variable, and it should work, or you can reset it to SQLite.
It's an old post but maybe somebody will find this useful.
In my case I had the DATABASE_URL variable exported in ~/.bash_profile like so
# Postgres installation
export DATABASE_URL=postgres:///$(whoami)
On Linux it might be in ~/.bashrc file.
Just remove or comment out the export line if you don't use Postgres anymore or use AlienBishop's solution if you do.
As IliaAptsiauri mentioned, without DATABASE_URL variable applications should use settings from database.yml file.
Getting this error while learning tutorial from this site.
http://ruby.railstutorial.org/chapters/a-demo-app#sec-demo_users_resource
tried to run this rails command on windows
rails generate scaffold User name:string email:string
and getting such error as:
> .../lib/sqlite3.rb:6:in 'require':cannot load such file -- sqlite3/sqlite3_native(LoadError)
>../lib/sqlite3.rb:2:in rescue in <top(required) >
>../bundler/runtime.rb:72:in 'require'
>.../bundler/runtime.rb:72:in block (2 level)
>from bin/rails:4: in 'require'
>from bin/rails:4: in <main>
I have already tried other answers like adding directory of sqlite to PATH..(its already there C:\RailsInstaller\Ruby2.0.0\lib\ruby\gems\2.0.0\gems\sqlite3-1.3.7-x86-mingw32)..
sqlite3(1.3.7-x86-mingw32 )is there in my gem list but still getting this error.
I have also tried to put sqlite3ext.h and sqlite3.h into /ext folder but its not working
tried this command
gem install sqlite3 --platform=ruby -- --with-sqlite3-dir=C:/path/to/sqlite3
no results
here is the Content of my database.yml
here is the database.yml file contents
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
UPDATE:
As adviced by one the user which really help me " you'll run into several problems that will be frustrating purely because on Windows. If you can't remove Windows, download Virtual Box and use a Linux Distro on it. It will make life much easier for you." Switching to Linux resolved everything. thanks https://stackoverflow.com/users/1092260/althaf-hameez for this advice.
See https://stackoverflow.com/a/16748607/2466276.
My actions:
1. Download http://packages.openknapsack.org/sqlite/sqlite-3.7.15.2-x86-windows.tar.lzma
2. Unpack to C:\Knapsack\x86
3. gem uninstall sqlite3
4. gem install sqlite3 --platform=ruby -- --with-opt-dir=C:/Knapsack/x86
The symptom of my problem is pretty simple:
$ rake db:create
(in /home/jason/projects/blog)
rake aborted!
no such file to load -- pg
(See full trace by running task with --trace)
I've already successfully run bundle install and gem install pg, so I don't know what else I might need to do.
Here's my `config/database.yml if it helps:
# SQLite version 3.x
# gem install sqlite3-ruby (not necessary on OS X Leopard)
development:
adapter: postgresql
encoding: unicode
database: blog_development
pool: 5
username: blog
password: foo
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: postgresql
encoding: unicode
database: blog_development
pool: 5
username: blog
password: foo
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
I figured it out. If I use pg instead of postgresql in my config/database.yml, it works.
Go to console and type below:
vim Gemfile
Inside the file commend the below:
- #gem 'sqlite3-ruby', :require => 'sqlite3'
Inside the file add the below:
- gem 'pg', :require => 'pg'
Problem Solved!!! :-) Enjoy!
One possibility is that the rake binary that you are running is from another ruby/gem environment and that it doesn't have access to the gems that you've installed.
If you have more than one version of ruby installed, try running which gem and then which rake to see if they are being run from the same bin directory. For example, on my machine both binaries are executed from bin directories under the same Ruby install:
/Users/scott/.rvm/rubies/ruby-1.9.2-p136/bin/gem
/Users/scott/.rvm/gems/ruby-1.9.2-p136/bin/rake
If you only have one ruby version installed on your system, then this isn't the answer!
I'm trying to deploy my first app to Heroku. I'm using SQLite as the database. As far as I know Heroku doesn't use SQLite - it switches to Postgres in the backend.
When I'm deploying I get the following error:
/usr/ruby1.8.7/lib/ruby/gems/1.8/gems/bundler-1.0.0/lib/bundler/runtime.rb:64:in
`require': no such file to load --
sqlite3 (LoadError)
My Gemfile (which is what I assume is causing this problem) looks as follows:
source 'http://rubygems.org'
gem 'rails', '3.0.0'
gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3'
What am I doing wrong?
Heroku doesn't support SQLite databases. You need to use PostgreSQL on production, as I also explained in this post.
group :production do
gem "pg"
end
group :development, :test do
gem "sqlite3", "~> 1.3.0"
end
Actually, it's recommended to use in development/test an environment as close as possible to production. Therefore, I suggest you to switch all your environments to PostgreSQL.
# replace gem "sqlite3" with
gem "pg"
Simone Carletti is correct and so is Joost. You only need to group the sqlite3 gem or remove it entirely from your Gemfile. Heroku just needs to know that you don't want to use sqlite3 for production
So this:
...
group :development, :test do
gem "sqlite3-ruby", "~> 1.3.0", :require => "sqlite3"
end
...
Or this:
...
#No reference to sqlite3-ruby
...
If you remove the reference entirely you will probably mess up your local db though
After banging my head against this problem, I realized I was pushing the master branch of my repo to heroku, while I was making all of my postgres changes in my deploy-postgres branch of my repo!
I merged my deploy-postgres branch with my local master [git checkout master; git merge deploy-postgres] and then could run git push heroku master as per the heroku documentation.
I was stuck on this for hours looking at every answer here, but I couldn't get enough details to make it come together. This paged walked me through everything. http://railsapps.github.io/rails-heroku-tutorial.html
Good luck.
i was facing similar issue, but I realized that I was on a different branch - new_layout and was pushing master.
So I pushed my desired branch to heroku using following command and everything worked fine.
git push heroku new_layout:master
You can use clearDB addon
and gem 'mysql2' instead of gem 'sqlite3'
I'm using sqlite3 and deploy to Heroku no problem. Here is my database.yml
# SQLite version 3.x
# gem install sqlite3-ruby (not necessary on OS X Leopard)
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000