I am trying to deploy my app to Heroku.
I removed the 'sqlite3' gem and added the following part to my Gemfile:
gem 'sqlite3', group: :development
group :production do
gem 'pg'
gem 'rails_12factor'
end
After that, I ran bundle install to update it. However, when I try to do git add, it said:
error: insufficient permission for adding an object to repository database.git/objects
error: Gemfile.lock: failed to insert into database
error: unable to index file Gemfile.lock
fatal: updating files failed
If I delete the code I added in the Gemfile, everything works just fine!
I'm running on OSX 10.11.1, Rails 4.2.4, ruby 2.2.1p85 and git 2.4.9 (Apple Git-60).
The issue is probably because your config/database.yml needs to be configured to use postgresql instead of sqlite.
I highly suggest using postgres for both production AND development by removing the gem 'sqlite3', group: :development from your gemfile and just add gem 'pg' outside of the production group (so it applies to all environments: dev, prod, and test).
Then in your database.yml, in the default: &default section, change adapter to:
adapter: postgresql
Or if you want to continue using sqlite in dev, just change the production: section in your database.yml to the following:
production:
adapter: postgresql
encoding: unicode
pool: 5
You might need to change the database: value to something like:
database: your_app_name_production
where "your_app_name" is the name of your app.
NOTE: Be sure to keep the spacing exact as YAML files are whitespace sensitive.
Hope that helps.
Or it could be something wrong with your Gemfile.lock.
You should be able to safely delete that file (make a backup copy first, just in case). Use git rm Gemfile.lock. Gemfile.lock just tracks all the versions of all the gems installed in your project based on the latest version at the point in time you first bundle installed them.
Then when you run bundle install it will automatically generate a new one.
Then do a git add -A again (better to use that than git add *).
Related
I have about 3 apps on a Windows Server 2012 and all of them are different versions of rails. So far, I can run locally the app with the latest version of rails, but not the other two, which were deployed from Heroku. I wanted to make changes locally before I push them to Heroku but no luck. Is there any reference to that or is this even possible? thanks a lot!
Your problem is that you are trying to use sqlite with Heroku. Heroku requires using 'postgres' as the database
change the gemfile to the following
group :development do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
And then change your database.yml file to this
adapter: postgresql
I am starting rails by following this tutorial:
http://ruby.railstutorial.org/ruby-on-rails-tutorial-book#sec-the_first_application
which seems very nice.
At the beginning, the author talks about the importance of the versions for the gems and softwares, so I did my best to keep using the exact same versions.
I followed the tutorial and it all ran nicely, the installation was ok (from his suggested source: http://railsinstaller.org/en )I downloaded ruby 1.9.
After installing, I used rails new first_app to create my app, changed the Gemfile to this one:
source 'https://rubygems.org'
ruby '1.9.3' #In the tutorial is 2.0.0, but changed to match my ruby version,
#as specified in the tutorial
#ruby-gemset=railstutorial_rails_4_0
gem 'rails', '4.0.1'
group :development do
gem 'sqlite3', '1.3.8'
end
gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
group :doc do
gem 'sdoc', '0.3.20', require: false
end
When I run rails server command, I get the following error:
DEPRECATION WARNING: config.whiny_nils option is deprecated and no longer works.
(called from block in <top (required)> at D:/rails/first_app/config/environment
s/development.rb:10)
config.eager_load is set to nil. Please update your config/environments/*.rb fil
es accordingly:
* development - set it to false
* test - set it to false (unless you use a tool that preloads your test enviro
nment)
* production - set it to true
But opening localhost:3000 works fine. Clicking on "About your application’s environment" link, generates an error
ActiveRecord::ConnectionNotEstablished
Rails.root: D:/rails/first_app
I checked and my database.yml is using sqlite3.
When I run rake db:create inside my app's folder, I get
rake aborted!
Specified 'postgresql' for database adapter, but the gem is not
loaded. Add gem 'pg' to your Gemfile.
I think that maybe these three issues are connected and the source of the problem is that error message when starting the rails server.
What can I do to fix it, could it be the ruby version 1.9.3 instead of 2.0.0?
thanks!
EDIT:
On this link, I found the solution for my issue on the whiny_nils deprecation
Rails 4 removed the whiny_nils feature. Read more about it in the ActiveRecord chapter.
To solve the deprecation warning, simply remove any lines that set config.whiny_nils. Rails 3 added the configuration by default in config/environments/development.rb and config/environments/test.rb by default.
No idea why creating an app and starting it with the same version would cause this problem, but ok. No.1 fixed :)
Edit2: In the same link, I fixed the config.eager_load issue by creating this config in my config files and setting a value.
The active record issue remains.
EDIT 3:
This is my database.yml file
# 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
Solved: I had a database_url pointing to a postgres DB in my system environment variables. I've done that when following an heroku tutorial long ago. I removed it and now it works fine.
I suggest a solution that I believe will work better for you:
Remove the version numbers from all of the gems other than rails
It will do rails 4 and ruby 2.0 and for you ruby 2.0 will probably work.
If necessary have the ruby version as 1.9.3
This would probably work better for you now and in the future.
It's better to avoid all those specific version numbers for other gems to avoid having.... the version problems you are experiencing. You want to spend less time on that and more time on the actual app, rails code, ruby code, etc. Most gems can figure out the right versions and dependencies themselves.
Try quickly doing another app this way (make sure you "cd .." out of this app first before issuing that rails new command again). You'll also see that doing a new app is a surprisingly frequent thing when compared to some other, older frameworks.
I am suffering from the infamous SQLite3 Vs Heroku error while trying to deploy a simple Rails app.
Initially my Gemfile looked like
gem 'sqlite3'
...
After googling on the topic, I updated it to look like this:
group :development, :test do
gem 'sqlite3'
end
...
and then did a bundle install and surprisingly (at least for me),
$ git status --short
M Gemfile
The Gemfile.lock did NOT change!
Now heroku keeps giving this SQLite error again and again because
the Gemfile.lock is same as before and bundle install keeps failing
on their server!
Where am I going wrong?
Damn! It was a git issue.
I was working on a branch named 'deploy' and trying to push the 'master' branch and hence bundle install failed every time!
$git push heroku deploy:master
This made it work :)
Rails 3.2.1, Ruby 1.9.3
I can push my app to Heroku, but when I navigate to the page it fails. This is from the logs:
"Unexpected error while processing request: Please install the postgresql adapter: 'gem install activerecord-postgresql-adapter'"
I have already run that command locally and it worked.
I am using sqlite3 for dev, my gemfile looks like this:
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'thin'
gem 'pg'
end
Any idea what I am doing wrong/how to fix this? thank you!
I'm getting the same sort of error with the same sort of config.
2013-04-05T08:06:12+00:00 app[web.1]: Connecting to database specified by DATABASE_URL
2013-04-05T08:06:12+00:00 app[web.1]: !! Unexpected error while processing request: Please install the postgresql adapte
r: `gem install activerecord-postgresql-adapter` (pg is not part of the bundle. Add it to Gemfile.)
Have found that doing an update to the Gemfile (just adding whitespace) gets around the problem. It's a hassle though since it needs to be done every time any change is done.
I have run 'heroku db:push' to download heroku db updates, it show me error:
taps load error: no such file to load --sqlite3
you may need to install or update the taps gem to use db commands.
on most systems this will be: sudo gem install taps
I have installed heroku 2.25.0, taps 0.3.24 and I changed the Gemfile replacing gem sqlite3 with:
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
I think it's a problem of compatibility database between sqlite e postgresql.
is it possible? Or what can be ?
First, make sure you've got your gems all up to date by running bundle install. It won't hurt if everything's fine so you may as well make sure.
After that, you should be able to use db:pull to pull a copy to your local machine using the snippet that follows:
bundle exec heroku db:pull sqlite://local.db --app my_app
If this doesn't work for some reason, you can just change your Gemfile while pulling the database down -- and then you can change it back if you want to.
group :development, :test do
gem 'sqlite3'
# add this next line and run 'bundle install' until you get db:pull to work
gem 'pg'
end
group :production do
gem 'pg'
end
(I believe this will work, though I personally haven't tried it. Please respond if there's an issue.)
Finally, there are some issues pulling and pushing databases if you're running ruby 1.9.3 on your local machine -- but it's only if you're doing a db:push. If you have problems with that here's a link to the solution.
When you run the heroku command, it runs locally on your development machine. So the development group of your Gemfile is used:
group :development, :test do
gem 'sqlite3'
end
Since it contains sqlite3, you need the sqlite3 gem to be installed on your development machine. Have you run bundle install to install this gem locally? And you may need to run the heroku command within a bundle exec call to make sure the gems are loaded:
bundle exec heroku db:pull.
Finally, if you want to download Heroku DB, you should use db:pull, not db:push.