sqlite3和heroku的问题

时间:2015-05-24 00:05:25

标签: heroku sqlite sinatra heroku-postgres sqlite3-ruby

每次我尝试在Heroku上学习时,我的应用程序都会崩溃(学校项目需要)。它在当地完美运作。

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.

以下是日志的说法:

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看起来像这样

    # 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
...

当我输入heroku运行控制台

要求' ./ main'

我明白了:

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>'

关于我能做什么的任何建议?

1 个答案:

答案 0 :(得分:1)

你收到此错误是因为heroku没有使用postgresql的Sqlite适配器。因此,您需要跳过在Heroku上使用Sqlite适配器。

  1. 如果您使用的是DataMapper,请使用下面的内容 -
  2. DataMapper :: setup(:default,ENV [&#39; DATABASE_URL&#39;] ||&#34; sqlite3:您的数据库文件名&#34;)

    1. 检查您是否遵循以下步骤。也许你可以从下面做几步,所以忽略这些并继续其余的步骤。
    2. <强> 1。在Heroku网站注册:

      https://id.heroku.com/login(指向外部网站的链接。)

      1. 下载工具栏

      2. 获取捆绑宝石

          

        gem install bundler

      3. 创建&#34; Gemfile&#34;在应用程序目录

      4. 它将创建&#34; Gemfile.lock&#34;文件在您的应用程序目录中。

      5.   

        捆绑安装 - 无需生产

        1. 创建&#34; config.ru&#34;机架式程序的文件包含
        2. 要求&#39; ./ main&#39;

          运行Sinatra :: Application

          1. 初始化git存储库,在您的应用程序文件夹中运行:
          2.   

            git init

            1. 设置git identity:
            2.   

              git config user.name&#34; your-name&#34;

                   

              git config user.email&#34; yourname@email.com"

              1. 将应用程序添加到git存储库并提交,在您的应用程序文件夹中运行:
              2.   

                git add。

                     

                git commit -m&#34;我的第一个版本&#34;

                1. 在Heroku上创建应用
                2.   

                  heroku创建myapplication1

                  1. 将应用程序从git存储库推送到Heroku服务器
                  2.   

                    git push heroku master

                    <强> 12。在Heroku服务器上创建数据库

                      

                    heroku运行控制台

                    IRB&GT;要求&#39; ./ main&#39;

                    IRB&GT; DataMapper.auto_migrate!

                      

                    连接到新网站

                         

                    heroku open