Heroku deployment failed because of sqlite3 gem error

后端 未结 5 1782
太阳男子
太阳男子 2020-11-28 13:45

I just started the ruby.railstutorial.org book by Michael Hartl and have been working through the first chapter. I am using mac book OS X, Terminal, and Sublime Text. Every

相关标签:
5条回答
  • 2020-11-28 13:57

    On Heroku, your app doesn't have access to the filesystem. There's a number of reasons for this - it's basically due to the fact that you can scale your app's performance by adding new instances (i.e. running multiple servers at once), and these instances aren't guaranteed to be on the same physical machine - copying the files across would be extremely slow.

    SQLite just stores the database to a file in your db/ folder, which is why it's incompatible with Heroku.

    The best option, as suggested in the help link, is to move away from SQLite, because there are sometimes subtle incompatibilities between SQLite and PostgreSQL (Heroku's database of choice) and you want to find this out before you deploy to production!

    After you install PostgreSQL (exactly how to do this depends on your OS) and then add gem 'pg' to your Gemfile.

    0 讨论(0)
  • 2020-11-28 14:00

    Heroku do not support sqlite3...

    Remove sqlite3 from your Gemfile, use pg gem instead. Do following change in gem file

    change following in your Gemfile

    gem 'sqlite3'
    

    to

    gem 'pg' #you will have to install postgresql
    

    Important: Run

    git add .
    git commit 
    git push heroku master
    

    Note: If you are planning to deploy for heroku, I suggest it is better to use postgres in your development phase also(install postgresql in your computer), heroku prefer psql.

    If you want to use sqllite for development and postgresql for Heroku, use following config.

    group :development do 
       gem 'sqlite3'    #gem to use in development environment
    end
    
    group :production do 
      gem 'pg'         #gem to use in production environment
    end
    

    Heroku will use pg gem since heroku run your application in production enviroment

    0 讨论(0)
  • 2020-11-28 14:01

    I was finally able to deploy successfully to Heroku. Thanks to evanc3 for pointing me to an article on the Heroku site. It appears that I simply forgot to commit my Gemgile updates before deploying to Heroku. So for all of you just starting out, you need to make sure you commit your changes before deploying to Heroku.

    0 讨论(0)
  • 2020-11-28 14:17

    Heroku can't install the sqlite3 gem, for whatever reason. But you can tell bundler that it shouldn't be trying to except when developing.

    In your Gemfile, replace gem 'sqlite3' with:

    group :development, :test do
      gem 'sqlite3'
    end
    group :production do
      gem 'pg'
    end
    

    Then bundler on heroku, running as production, won't try to install it.

    0 讨论(0)
  • 2020-11-28 14:21

    I have a solution for if you don't have sqlite3 directly in your gemfile and you're still getting this error.

    Most likely, you have a gem that uses sqlite3 as a dependency and it's including the gem without you knowing.

    1) Go to Gemfile.lock and do a search for sqlite.

    2) Locate which gem is using sqlite then move the gem into the development or test group.

    3) Bundle

    0 讨论(0)
提交回复
热议问题