Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issues with sqlite3 and heroku

My app is crashing every time I try to get it on Heroku (required for a school project). It works perfectly locally.

An error occurred in the application and your page could not be served. Please try again in a few moments.

If you are the application owner, check your logs for details.

Here is what the logs say:

2015-05-23T23:52:47.952635+00:00 heroku[web.1]: State changed from crashed to starting
2015-05-23T23:52:50.499347+00:00 heroku[web.1]: Starting process with command `bundle exec thin start -R config.ru -e $RACK_ENV -p 10414`
2015-05-23T23:52:52.736994+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/dm-core-1.2.1/lib/dm-core/adapters.rb:163:in `require': cannot load such file -- dm-sqlite-adapter (LoadError)
...
2015-05-23T23:53:11.790209+00:00 heroku[run.9012]: Awaiting client
2015-05-23T23:53:11.844408+00:00 heroku[run.9012]: Starting process with command `bundle exec irb`
2015-05-23T23:53:12.025719+00:00 heroku[run.9012]: State changed from starting to up
2015-05-23T23:54:03.317467+00:00 heroku[run.9012]: Process exited with status 0
2015-05-23T23:54:03.336441+00:00 heroku[run.9012]: State changed from up to complete
2015-05-23T23:54:08.767294+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=mysterious-woodland-2551.herokuapp.com request_id=a53bb16e-88e6-4701-857f-bd3319ce8d91 fwd="129.210.115.16" dyno= connect= service= status=503 bytes=
2015-05-23T23:54:09.427490+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=mysterious-woodland-2551.herokuapp.com request_id=8effbba8-b14f-4b8a-bb2f-a7a4eae5e44c fwd="129.210.115.16" dyno= connect= service= status=503 bytes=

My Gemfile looks like this

    # A sample Gemfile
    source "https://rubygems.org"
    ruby '2.0.0'

    gem 'sinatra'
    gem 'slim'
    gem 'sass'
    gem 'dm-core'
    gem 'dm-migrations'
    gem 'thin'
    group :development, :test do
      gem 'sqlite3'
    end

    group :production do
      gem 'pg'
    end

main.rb

#!/user/bin/env ruby

require 'sinatra'
require 'slim'
require 'sass'
require './student'

configure do
  enable :sessions
  set :username, 'kenneth'
  set :password, 'bigler'
end

get('/styles.css'){ scss :styles }

get '/' do
  slim :home
end
...

student.rb

require 'dm-core'
require 'dm-migrations'

# DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/development.db")
DataMapper::setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/development.db")

class Student
  include DataMapper::Resource
  property :id, Serial
  property :first_name, Text
  property :last_name, Text
  property :year, Integer
end

configure do
  enable :sessions
  set :username, 'kenneth'
  set :password, 'bigler'
end

DataMapper.finalize

get '/students' do
...

when I type heroku run console

require './main'

I get:

LoadError: cannot load such file -- dm-sqlite-adapter
    from /app/vendor/bundle/ruby/2.0.0/gems/dm-core-1.2.1/lib/dm-core/adapters.rb:163:in `require'
    from /app/vendor/bundle/ruby/2.0.0/gems/dm-core-1.2.1/lib/dm-core/adapters.rb:163:in `load_adapter'
    from /app/vendor/bundle/ruby/2.0.0/gems/dm-core-1.2.1/lib/dm-core/adapters.rb:133:in `adapter_class'
    from /app/vendor/bundle/ruby/2.0.0/gems/dm-core-1.2.1/lib/dm-core/adapters.rb:13:in `new'
    from /app/vendor/bundle/ruby/2.0.0/gems/dm-core-1.2.1/lib/dm-core.rb:230:in `setup'
    from /app/student.rb:5:in `<top (required)>'
    from /app/main.rb:6:in `require'
    from /app/main.rb:6:in `<top (required)>'
    from (irb):1:in `require'
    from (irb):1
    from /app/bin/irb:16:in `<main>'

Any suggestions on what I can do?

like image 536
Ken Bigler Avatar asked Jul 01 '26 08:07

Ken Bigler


1 Answers

you are getting this error because heroku doesn't have Sqlite adapter it uses postgresql. So you will need to skip the use of Sqlite adapter on Heroku.

  1. if you are using DataMapper then use it like below-

DataMapper::setup(:default, ENV['DATABASE_URL'] || "sqlite3:your database file name")

  1. check if you are following below steps or not. May be you could have done few steps from below so ignore those and follow the rest.

1. Sign up at Heroku website:

https://id.heroku.com/login (Links to an external site.)

  1. Download toolbelt

  2. get bundler gem:

    gem install bundler

  3. create "Gemfile" in application directory:

  4. It will create "Gemfile.lock" file in your application directory.

bundle install --without production

  1. create "config.ru" file for rackup program with below contains

require './main'

run Sinatra::Application

  1. initialize git repository, in your application folder, run:

git init

  1. set git identity:

git config user.name "your-name"

git config user.email "[email protected]"

  1. add application to git repository and commit, in your application folder, run:

git add .

git commit -m "my first version"

  1. create application on Heroku

heroku create myapplication1

  1. push application from git repository to Heroku server

git push heroku master

12. create database on Heroku server

heroku run console

irb> require './main'

irb> DataMapper.auto_migrate!

connect to new web site

heroku open

like image 63
Neha Narlawar Avatar answered Jul 05 '26 18:07

Neha Narlawar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!