【问题标题】:ActiveRecord::StatementInvalid (SQLite3::ReadOnlyException: when using postgresActiveRecord::StatementInvalid (SQLite3::ReadOnlyException: 当使用 postgres
【发布时间】:2014-11-16 21:01:26
【问题描述】:

我正在尝试在 Ubuntu 的数字海洋上部署我的第一个 rails 应用程序,我不确定我是否做得对。我最初在 postgres 中有我的生产数据库,在 sqllite 中有测试和生产。沮丧的是,我将所有数据库都更改为 postgres,我更改了 database.yml。我不确定我这样做是否正确但是我遇到了这个错误:ActiveRecord::StatementInvalid (SQLite3::ReadOnlyException: 。当我在 sqllite 中时。我不确定我是否必须告诉服务器切换到生产模式或者是否它已配置为使用 sqllite。

我想做的是使用 postgres 而不是 sqllite。我正在使用 nginx 和 Unicorn。我的数据库是空白的,所以我不需要传输任何东西。我已经在 postgres 中创建了 postgres 数据库,我只需要将我的应用程序指向该数据库。 (我不知道我是否需要做其他事情

我用过这个database.yml

development:
  adapter: postgresql
  encoding: unicode
  host: localhost
  database: blog_development
  pool: 5
  username: bob
  password: password

test:
  adapter: postgresql
  encoding: unicode
  database: blog_test
  host: localhost
  pool: 5
  username: bob
  password: password

production:
  adapter: postgresql
  encoding: unicode
  host: localhost
  database: blog_production
  pool: 5
  username: bob
  password: password

宝石文件:

source 'https://rubygems.org'
ruby '2.0.0'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.4'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer',  platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

gem 'jquery-ui-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0',          group: :doc

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring',        group: :development

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

gem 'bootstrap-sass' # for using bootstrap-rails"

gem 'faker'

gem 'will_paginate'

gem 'annotate', '~> 2.6.5'

gem 'font-awesome-rails' # for using font-awesome icons

gem 'redcarpet', '~> 2.1.1'
gem 'coderay', '~> 1.1.0' # For nice code snippets


gem 'devise'

gem 'sidekiq'

gem 'haml-rails'

group :development do
  gem 'better_errors'
  gem 'binding_of_caller'
  gem 'meta_request'
  gem 'guard-rspec'
end

group :test do
  gem 'capybara'
  gem 'factory_girl_rails', '4.2.0'
end

gem 'pg', '0.15.1'

group :development, :test do
  gem 'rspec-rails'
  # Use sqlite3 as the database for Active Record in testing
end

group :production do

  gem 'rails_12factor', '0.0.2'
end

我的 github 上有其余代码:https://github.com/RubyQuarry/Bootstrap_blog

【问题讨论】:

  • 在什么情况下会出现该错误?当您尝试启动控制台时?运行服务器?
  • 当我尝试在104.236.51.180/blogs/10104.236.51.180/blogs/10写应用程序(发表评论)时发生这种情况
  • 你能运行rake db:drop db:create db:migrate吗?您可以登录到 Rails 控制台并通过该界面创建一个 Comment 对象吗?如果不是,错误是什么?
  • 更改数据库后是否重新启动所有内容?听起来您的应用程序仍然认为它正在与 SQLite 对话。
  • 我通过运行得到了它,rake db:drop db:create db:migrate 谢谢@Bryce

标签: ruby-on-rails postgresql sqlite web-deployment digital-ocean


【解决方案1】:

运行 rake db:drop db:create db:drop 删除旧数据库并在 Postgres 中重新创建新数据库。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-08
    • 1970-01-01
    • 2013-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-11
    相关资源
    最近更新 更多