ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

mysql-Capistrano“ cap deploy:migrations”失败,因为它尝试运行所有迁移,而不仅是正在运行的迁移

2019-12-08 01:15:12  阅读:229  来源: 互联网

标签:mysql2 capistrano ruby-on-rails-3 ruby-on-rails mysql


我尝试使用“ cap deploy:migrations”进行部署,因为我需要在实时服务器上执行3个新的迁移.结果是:

executing "cd /home/martin/public_html/project/releases/20110905131238; bundle exec rake RAILS_ENV=production  db:migrate"
    servers: ["50.56.82.190"]
    [50.56.82.190] executing command
 ** [out :: 50.56.82.190] ==  CreateUsers: migrating ====================================================
 ** [out :: 50.56.82.190] -- create_table(:users)
 ** [out :: 50.56.82.190] rake aborted!
 ** [out :: 50.56.82.190] An error has occurred, all later migrations canceled:
 ** [out :: 50.56.82.190] 
 ** [out :: 50.56.82.190] Mysql2::Error: Table 'users' already exists: CREATE TABLE `users` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `name` varchar(255), `email` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
 ** [out :: 50.56.82.190] 
 ** [out :: 50.56.82.190] Tasks: TOP => db:migrate
 ** [out :: 50.56.82.190] (See full trace by running task with --trace)
    command finished in 5816ms
failed: "sh -c 'cd /home/martin/public_html/project/releases/20110905131238; bundle exec rake RAILS_ENV=production  db:migrate'" on 50.56.82.190

通过先前的部署,我已经在实时服务器上创建了一个正常工作的数据库.我创建了3个新迁移(由于要使用新的gems carrierwave和rmagick上载图像),因此我希望现在进行部署.显然,请使用cap deploy:migrations尝试从第一个迁移运行所有迁移,而不仅仅是挂起的迁移.

我的deploy.rb是:

require 'bundler/capistrano'
set :application, "otg.in"
set :domain, "otg.in"
set :user, "martin"
set :sudo_use, false
set :repository, "git@github.com:Martin118/otg.in.git"
set :local_repository,  '~/rails_projects/otg.in/.git'
set :port, 48000
set :deploy_to, "/home/martin/public_html/#{application}"
set :scm, :git
set :branch, "master"
default_run_options[:pty] = true
ssh_options[:forward_agent] = true

server "50.56.82.190", :app, :web, :db, :primary => true

after "deploy", "deploy:bundle_gems"
after "deploy:bundle_gems", "deploy:restart"
after "deploy:update_code", "deploy:migrate"
after "deploy", "deploy:cleanup"

# Passenger
namespace :deploy do
     task :bundle_gems do
    run "cd #{deploy_to}/current && bundle install vendor/gems"
  end
  task :start do ; end
  task :stop do ; end
  task :restart, :roles => :app, :except => { :no_release => true } do
    run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
  end
end

require 'whenever/capistrano'

我运行rails 3.0.8,cap deploy:check给我“您似乎已安装了所有必要的依赖项”.

有任何想法吗?还是您需要更多信息?

谢谢你的帮助!

实时运行的schema.rb是:

ActiveRecord::Schema.define(:version => 20110130000344) do

  create_table "businesses", :force => true do |t|
    t.string   "business_name"
    t.string   "postal_code"
    t.string   "business_email"
    t.string   "phone"
    t.string   "fax"
    t.string   "web"
    t.text     "description"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.integer  "user_id"
    t.text     "address"
    t.integer  "city_id"
    t.integer  "state_id"
  end

  create_table "cities", :force => true do |t|
    t.string   "name"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.integer  "state_id"
  end

  create_table "states", :force => true do |t|
    t.datetime "created_at"
    t.datetime "updated_at"
    t.string   "name"
  end

  create_table "users", :force => true do |t|
    t.string   "name"
    t.string   "email"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.string   "encrypted_password"
    t.string   "salt"
    t.boolean  "admin",              :default => false
  end

  add_index "users", ["email"], :name => "index_users_on_email", :unique => true

end

另一个更新:从schema_migrations中选择*;在我的开发数据库上给我:

 —————-
|版本|
 —————-
| 20110112163009 |
| 20110113141953 |
| 20110113192958 |
| 20110114214158 |
| 20110115002206 |
| 20110119100832 |
| 20110120134443 |
| 20110127171331 |
| 20110127171427 |
| 20110127171921 |
| 20110127172903 |
| 20110127183252 |
| 20110129201949 |
| 20110129204159 |
| 20110129205833 |
| 20110130000344 |
| 20110808142844 |
| 20110809133339 |
| 20110809142303 |
| 20110809154349 |
| 20110810092306 |
| 20110810093531 |
| 20110812085010 |
 —————-

但是用我得到的MySQL工作台检查(仍然是开发数据库):

错误:project_development.schema_migrations:表数据不可编辑,因为没有为表定义主键

另外,生产数据库上的schema_migrations中的select *仅给我一个迁移(我尝试更新之前的最后一个迁移):

 —————-
|版本|
 —————-
| 0 |
| 20110130000344 |
 —————-

有人知道这里发生了什么吗?

谢谢!

解决方法:

解决方案是手动将缺少的迁移添加到schema_migrations中.似乎该表丢失了一些数据.无论如何,通过添加已经直接使用“将INSERT插入schema_migrations(版本)值(‘2011 ….’);”中的迁移,然后上限deploy:migrations从新迁移开始就可以顺利进行.

标签:mysql2,capistrano,ruby-on-rails-3,ruby-on-rails,mysql
来源: https://codeday.me/bug/20191208/2087913.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有