Capistrano SQLite3 :: SQLException:没有这样的表:用户

时间:2016-12-13 11:16:05

标签: ruby-on-rails ruby sqlite sinatra digital-ocean

Ubuntu 16,ruby,3.2,框架Sinatra。

上限部署后未在生产中运行迁移。

我使用命令cap deploy production将我的项目部署到远程服务器。

在db:

的app.rb连接设置中
#app.rb

require "sinatra"
require "pry"
require "sinatra/activerecord"
require 'sinatra/flash'
require 'sinatra/base'
require "./models/user"
require "./models/game_counter"
require "./models/stash"
require "json"
require "pony"
require 'logger'


enable :static
enable :sessions


set :public_folder, File.dirname(__FILE__) + '/assets'

set :database, { adapter: "sqlite3", database: "sudoku_database.sqlite3" }

的Gemfile

gem "rake"
gem "heroku"
gem "sinatra"
gem "sinatra-activerecord"
gem "sinatra-flash"
gem "sqlite3"
gem "pg"
gem "bcrypt"
gem "pry"
gem "pony"
gem "capistrano", '~> 3.1.0'
gem "capistrano-bundler", '~> 1.1.2'
gem 'passenger'

我在远程服务器上安装了sqllite。

安装和定制的capistrano。

配置/ deploy.rb

lock '3.4.0'

set :application, 'projectname'
set :repo_url, 'git@github.com:user/projectname.git'

set :deploy_to, '/home/deploy/projectname'

set :linked_dirs, %w{ log }


namespace :deploy do

  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      execute :touch, release_path.join('tmp/restart.txt')
    end
  end

  after :publishing, 'deploy:restart'
  after :finishing, 'deploy:cleanup'
end

配置/ production.rb

set :stage, :production

server '188.177.76.190', user: 'deploy', roles: %w{web app db}, port: 2503

当我在浏览器中运行网站时,在日志中显示nginx显示错误:

2016-12-13 10:40:58 - ActiveRecord::StatementInvalid - SQLite3::SQLException: no such table: users: SELECT "users".* FROM "user 

请帮助我,不能理解为什么不在生产中运行数据库迁移以及我如何解决这个问题?

2 个答案:

答案 0 :(得分:1)

在实时转到您的应用程序并在生产环境中的服务器上迁移数据库。

rake db:migrate RAILS_ENV=production

答案 1 :(得分:1)

迁移没有capistrano任务。您应该在部署配置中添加它。像这样(取决于你的配置):

task :migrate do
  on roles(:app) do
    within release_path do
      with rack_env: fetch(:rack_env) do
        execute :rake, "db:migrate"
      end
    end
  end
end

after 'deploy', 'migrate'