【问题标题】:Is it necessary to migrate the data base for update the app on heroku?是否需要迁移数据库以更新heroku上的应用程序?
【发布时间】:2014-01-28 08:16:41
【问题描述】:

这个应用程序“ecozap:http://www.ecozap.es/”是五年前由另一个开发者开发的,它已经发布,我必须进行设计更改和css样式......

该应用在 heroku v174 版本上运行。

是否需要迁移数据库进行更新并在heroku上推送应用程序?

我只更改了样式并添加了图像。

这是我的 database.yml 文件:

# SQLite version 3.x
#   gem install sqlite3
development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: sqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000

staging:
  adapter: sqlite3
  database: db/staging.sqlite3
  pool: 5
  timeout: 5000

production:
  adapter: sqlite3
  database: db/production.sqlite3
  pool: 5
  timeout: 5000

这是我的 Gemfile:

source 'http://rubygems.org'
ruby '1.9.3'

gem 'rails', "= 3.1.11"
#gem "rake", "= 0.8.7"
gem 'racc'
# gem 'sqlite3'
#gem 'acts_as_list', '>= 0.1.0'
#gem 'acts_as_tree'
gem 'paperclip'
gem 'aws-s3', :require => 'aws/s3'
gem 'aws-sdk'
gem 'gravatar_image_tag'
gem 'kaminari'
gem 'jquery-rails', '~> 2.1'
gem 'RedCloth', '>= 3.301'
gem 'carmen', :git => 'git://github.com/alvatarc/carmen.git', :branch => '0.2.x'
#gem 'carmen'
gem 'sass-rails'
gem 'http_accept_language'
gem 'right_aws'
gem 'exception_notification'#, '3.0.1'#añadido

group :development do
  gem 'sqlite3-ruby', :require => 'sqlite3'
  gem 'rspec-rails', '= 2.7.0'
  gem 'rspec-core', '= 2.7.1'
  gem 'rspec'
  #gem 'annotate-models'
  gem 'faker'
  gem 'therubyracer', :platform => 'ruby'
end

group :test do
  gem 'sqlite3-ruby', :require => 'sqlite3'
  gem 'rspec-rails', '= 2.7.0'
  gem 'rspec-core', '= 2.7.1'
  gem 'rspec'
  gem 'webrat'
  gem 'spork', '= 0.9.0.rc9'
  gem 'factory_girl_rails'
end

group :production do
  gem 'pg'
  gem 'uglifier'
end

当我推送到 heroku 时,我收到以下错误:

C:\Sites\ecozap>heroku logs --app ecozap
2014-01-28T09:31:23.706553+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.1.1
1/lib/action_dispatch/middleware/stack.rb:112:in `each'
2014-01-28T09:31:23.706553+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.1.1
1/lib/action_dispatch/middleware/stack.rb:112:in `inject'
2014-01-28T09:31:23.706774+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.11/
lib/rails/initializable.rb:30:in `instance_exec'
2014-01-28T09:31:23.706553+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.1.11/lib/ac
tion_dispatch/middleware/stack.rb:43:in `build': undefined method `new' for ExceptionNotifier:Module (No
MethodError)
2014-01-28T09:31:23.706648+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.1.1
1/lib/action_dispatch/middleware/stack.rb:112:in `build'
2014-01-28T09:31:23.706648+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.11/
lib/rails/engine.rb:447:in `app'
2014-01-28T09:31:23.706774+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.11/
lib/rails/application/finisher.rb:37:in `block in <module:Finisher>'
2014-01-28T09:31:23.706774+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.11/
lib/rails/application.rb:96:in `initialize!'
2014-01-28T09:31:23.706774+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.11/
lib/rails/initializable.rb:30:in `run'
2014-01-28T09:31:23.706774+00:00 app[web.1]:    from /app/config/environment.rb:5:in `<top (required)>'
2014-01-28T09:31:23.706774+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.11/
lib/rails/initializable.rb:54:in `run_initializers'
2014-01-28T09:31:23.706774+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.11/
lib/rails/railtie/configurable.rb:30:in `method_missing'
2014-01-28T09:31:23.706774+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.11/
lib/rails/initializable.rb:55:in `block in run_initializers'
2014-01-28T09:31:23.706975+00:00 app[web.1]:    from /app/config.ru:8:in `block in <main>'
2014-01-28T09:31:23.706975+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.3.10/lib/
rack/builder.rb:51:in `instance_eval'
2014-01-28T09:31:23.706975+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.3.10/lib/
rack/builder.rb:51:in `initialize'
2014-01-28T09:31:23.706975+00:00 app[web.1]:    from /app/config.ru:in `<main>'
2014-01-28T09:31:23.706774+00:00 app[web.1]:    from /app/config.ru:8:in `require'
2014-01-28T09:31:23.706975+00:00 app[web.1]:    from /app/config.ru:in `new'
2014-01-28T09:31:23.706975+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.3.10/lib/
rack/server.rb:304:in `wrapped_app'
2014-01-28T09:31:23.706975+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.3.10/lib/
rack/builder.rb:40:in `eval'
2014-01-28T09:31:23.706975+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.3.10/lib/
rack/server.rb:200:in `app'
2014-01-28T09:31:23.706975+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.3.10/lib/
rack/builder.rb:40:in `parse_file'
2014-01-28T09:31:23.706975+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.11/
lib/rails/commands/server.rb:46:in `app'
2014-01-28T09:31:23.706774+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.11/
lib/rails/initializable.rb:54:in `each'
2014-01-28T09:31:23.706975+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.3.10/lib/
rack/server.rb:254:in `start'
2014-01-28T09:31:23.707423+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.11/
lib/rails/commands/server.rb:70:in `start'
2014-01-28T09:31:23.707423+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.11/
lib/rails/commands.rb:54:in `block in <top (required)>'
2014-01-28T09:31:23.707423+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.11/
lib/rails/commands.rb:49:in `tap'
2014-01-28T09:31:23.707423+00:00 app[web.1]:    from script/rails:6:in `require'
2014-01-28T09:31:23.707423+00:00 app[web.1]:    from script/rails:6:in `<main>'
2014-01-28T09:31:23.707423+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.11/
lib/rails/commands.rb:49:in `<top (required)>'
2014-01-28T09:31:25.113332+00:00 heroku[web.1]: Error R12 (Exit timeout) -> At least one process failed
to exit within 10 seconds of SIGTERM
2014-01-28T09:31:25.113517+00:00 heroku[web.1]: Stopping remaining processes with SIGKILL
2014-01-28T09:31:25.239226+00:00 heroku[web.1]: Process exited with status 1
2014-01-28T09:31:25.254967+00:00 heroku[web.1]: State changed from starting to crashed
2014-01-28T09:31:25.256579+00:00 heroku[web.1]: State changed from crashed to starting
2014-01-28T09:31:26.892077+00:00 heroku[web.1]: Process exited with status 137
2014-01-28T09:31:29.944119+00:00 heroku[web.1]: Starting process with command `bundle exec rails server
-p 15889`
2014-01-28T09:31:33.583232+00:00 app[web.1]: Your Gemfile lists the gem sqlite3-ruby (>= 0) more than on
ce.
2014-01-28T09:31:33.583232+00:00 app[web.1]: You should probably keep only one of them.
2014-01-28T09:31:33.583232+00:00 app[web.1]: You should probably keep only one of them.
2014-01-28T09:31:33.583232+00:00 app[web.1]: While it's not a problem now, it could cause errors if you
change the version of just one of them later.
2014-01-28T09:31:33.583232+00:00 app[web.1]: While it's not a problem now, it could cause errors if you
change the version of just one of them later.
2014-01-28T09:31:33.583232+00:00 app[web.1]: Your Gemfile lists the gem rspec-rails (= 2.7.0) more than
once.
2014-01-28T09:31:33.583232+00:00 app[web.1]: Your Gemfile lists the gem rspec (>= 0) more than once.
2014-01-28T09:31:33.583428+00:00 app[web.1]: You should probably keep only one of them.
2014-01-28T09:31:33.583232+00:00 app[web.1]: You should probably keep only one of them.
2014-01-28T09:31:33.583232+00:00 app[web.1]: While it's not a problem now, it could cause errors if you
change the version of just one of them later.
2014-01-28T09:31:33.583232+00:00 app[web.1]: Your Gemfile lists the gem rspec-core (= 2.7.1) more than o
nce.
2014-01-28T09:31:33.583428+00:00 app[web.1]: While it's not a problem now, it could cause errors if you
change the version of just one of them later.
2014-01-28T09:31:44.462215+00:00 app[web.1]: => Booting WEBrick
2014-01-28T09:31:44.462215+00:00 app[web.1]: => Call with -d to detach
2014-01-28T09:31:44.462215+00:00 app[web.1]: => Rails 3.1.11 application starting in production on http:
//0.0.0.0:15889
2014-01-28T09:31:44.463228+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.1.1
1/lib/action_dispatch/middleware/stack.rb:112:in `inject'
2014-01-28T09:31:44.463228+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.1.1
1/lib/action_dispatch/middleware/stack.rb:112:in `build'
2014-01-28T09:31:44.462215+00:00 app[web.1]: Exiting
2014-01-28T09:31:44.463228+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.1.11/lib/ac
tion_dispatch/middleware/stack.rb:43:in `build': undefined method `new' for ExceptionNotifier:Module (No
MethodError)
2014-01-28T09:31:44.463228+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.1.1
1/lib/action_dispatch/middleware/stack.rb:112:in `block in build'
2014-01-28T09:31:44.463228+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.1.1
1/lib/action_dispatch/middleware/stack.rb:112:in `each'
2014-01-28T09:31:44.463228+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.11/
lib/rails/engine.rb:447:in `app'
2014-01-28T09:31:44.463228+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.11/
lib/rails/application/finisher.rb:37:in `block in <module:Finisher>'
2014-01-28T09:31:44.462215+00:00 app[web.1]: => Ctrl-C to shutdown server
2014-01-28T09:31:44.463228+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.11/
lib/rails/initializable.rb:30:in `instance_exec'
2014-01-28T09:31:44.463441+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.11/
lib/rails/initializable.rb:54:in `run_initializers'
2014-01-28T09:31:44.463441+00:00 app[web.1]:    from /app/config/environment.rb:5:in `<top (required)>'
2014-01-28T09:31:44.463441+00:00 app[web.1]:    from /app/config.ru:8:in `block in <main>'
2014-01-28T09:31:44.463441+00:00 app[web.1]:    from /app/config.ru:8:in `require'
2014-01-28T09:31:44.463228+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.11/
lib/rails/initializable.rb:55:in `block in run_initializers'
2014-01-28T09:31:44.463228+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.11/
lib/rails/initializable.rb:30:in `run'
2014-01-28T09:31:44.463441+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.11/
lib/rails/initializable.rb:54:in `each'
2014-01-28T09:31:44.463612+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.3.10/lib/
rack/server.rb:200:in `app'
2014-01-28T09:31:44.463612+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.11/
lib/rails/commands/server.rb:46:in `app'
2014-01-28T09:31:44.463441+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.3.10/lib/
rack/builder.rb:51:in `instance_eval'
2014-01-28T09:31:44.463441+00:00 app[web.1]:    from /app/config.ru:in `new'
2014-01-28T09:31:44.463441+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.3.10/lib/
rack/builder.rb:51:in `initialize'
2014-01-28T09:31:44.463441+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.11/
lib/rails/railtie/configurable.rb:30:in `method_missing'
2014-01-28T09:31:44.463612+00:00 app[web.1]:    from /app/config.ru:in `<main>'
2014-01-28T09:31:44.463612+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.3.10/lib/
rack/builder.rb:40:in `eval'
2014-01-28T09:31:44.463441+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.11/
lib/rails/application.rb:96:in `initialize!'
2014-01-28T09:31:44.464071+00:00 app[web.1]:    from script/rails:6:in `require'
2014-01-28T09:31:44.463612+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.11/
lib/rails/commands.rb:54:in `block in <top (required)>'
2014-01-28T09:31:44.464071+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.11/
lib/rails/commands.rb:49:in `<top (required)>'
2014-01-28T09:31:44.463612+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.11/
lib/rails/commands.rb:49:in `tap'
2014-01-28T09:31:44.463612+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.3.10/lib/
rack/server.rb:304:in `wrapped_app'
2014-01-28T09:31:44.463612+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.11/
lib/rails/commands/server.rb:70:in `start'
2014-01-28T09:31:44.464071+00:00 app[web.1]:    from script/rails:6:in `<main>'
2014-01-28T09:31:44.463612+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.3.10/lib/
rack/server.rb:254:in `start'
2014-01-28T09:31:44.463612+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.3.10/lib/
rack/builder.rb:40:in `parse_file'
2014-01-28T09:31:46.058892+00:00 heroku[web.1]: Process exited with status 1
2014-01-28T09:31:46.069301+00:00 heroku[web.1]: State changed from starting to crashed
2014-01-28T09:31:47.241185+00:00 heroku[nginx]: 87.218.164.248 - - [28/Jan/2014:09:31:47 +0000] "GET /?l
ocale=es HTTP/1.1" 503 409 "http://www.ecozap.es/?locale=es" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/5
37.36 (KHTML, like Gecko) Chrome/32.0.1700.76 Safari/537.36" www.ecozap.es
2014-01-28T09:31:47.240108+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/?
locale=es host=www.ecozap.es request_id=cf3976b7-4c4b-4d11-b3dd-036cfc5c1ddb fwd="87.218.164.248" dyno=
connect= service= status=503 bytes=
2014-01-28T09:31:50.354991+00:00 heroku[nginx]: 5.10.83.26 - - [28/Jan/2014:09:31:50 +0000] "GET /carts/
918632?locale=es HTTP/1.1" 503 409 "-" "Mozilla/5.0 (compatible; AhrefsBot/5.0; +http://ahrefs.com/robot
/)" www.ecozap.es
2014-01-28T09:31:50.335416+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/c
arts/918632?locale=es host=www.ecozap.es request_id=7f03696d-14bb-422c-befa-48cf359ab21f fwd="5.10.83.26
" dyno= connect= service= status=503 bytes=
2014-01-28T09:30:08.610174+00:00 heroku[router]: at=info method=GET path=/?locale=es host=www.ecozap.es
request_id=7e7f92e3-94ad-47a0-9154-90655af1633c fwd="87.218.164.248" dyno=web.1 connect=1ms service=125m
s status=304 bytes=0
2014-01-28T09:30:09.487341+00:00 heroku[router]: at=info method=GET path=/assets/bg-e370e1a45db2fb66fee9
eb2ac688e649.png host=www.ecozap.es request_id=15ef80ef-0429-4f81-bf21-dca347746082 fwd="87.218.164.248"
 dyno=web.1 connect=4ms service=7ms status=304 bytes=0
2014-01-28T09:30:09.167444+00:00 heroku[router]: at=info method=GET path=/assets/CO2-plus-abfd84d445691d
3ace3d797cee661210.jpg host=www.ecozap.es request_id=bd87c4ae-90f3-4c27-a245-c79a836ea13e fwd="87.218.16
4.248" dyno=web.1 connect=1ms service=6ms status=304 bytes=0
2014-01-28T09:30:09.521797+00:00 heroku[router]: at=info method=GET path=/assets/eco-253306c2a7299a16c10
9b71d8374e37c.jpg host=www.ecozap.es request_id=f58b7f21-e986-4e56-a668-257df0fc39b1 fwd="87.218.164.248
" dyno=web.1 connect=2ms service=6ms status=304 bytes=0
2014-01-28T09:30:09.464954+00:00 heroku[router]: at=info method=GET path=/assets/eco-over-83ea6faa95bd9d
c45c1237aeb4624d00.jpg host=www.ecozap.es request_id=2979b3a4-e8d8-4cbc-94b1-253531753fa4 fwd="87.218.16
4.248" dyno=web.1 connect=1ms service=5ms status=304 bytes=0
2014-01-28T09:30:09.460994+00:00 heroku[router]: at=info method=GET path=/assets/women-over-44ae6e42fc1e
999038afe5485af27c60.jpg host=www.ecozap.es request_id=708ee385-433b-49e8-a3c1-e8342408fbe9 fwd="87.218.
164.248" dyno=web.1 connect=1ms service=5ms status=304 bytes=0

C:\Sites\ecozap>

【问题讨论】:

  • 如果您只更改样式等,则不需要迁移数据库。
  • Serigo,在将我的应用程序推送到 Heroku 之前,我在生产模式下测试了我的应用程序,如果它在开发模式下它可以完美运行,但在生产模式下我收到以下错误 activerecord -3.1.11找不到表(ActiveRecord::Statement Invalid)。
  • 在其他帖子中有人告诉我必须迁移才能解决此错误。
  • @FrankyCutty,您在本地使用通用数据库进行开发和生产吗?
  • @FrankyCutty:你在本地机器上使用过生产模式吗?它使用不同的数据库,可能在本地尚不存在(但应该存在于 heroku)(appname_production vs appname_development)

标签: ruby-on-rails heroku rake push


【解决方案1】:

不需要迁移数据库进行更新并在heroku上推送应用程序。

迁移部分与部署不同,因此您无需迁移即可轻松部署。

编辑: 假设您只想在本地测试生产环境

更改您的 database.yml 以使用与开发相同的数据库。这样您就不需要更改 gemfile 并且可以使用您的开发环境测试生产环境

重要提示:编译测试后回滚到原始 database.yml

development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: sqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000

staging:
  adapter: sqlite3
  database: db/staging.sqlite3
  pool: 5
  timeout: 5000

production:
  adapter: sqlite3
  database: db/development.sqlite3 #<==This is the change
  pool: 5
  timeout: 5000

【讨论】:

  • 在其他帖子中有人告诉我必须迁移才能解决此错误。 this is the post。我很困惑。
  • @Franky,我认为您应该考虑 Marek Lipka 的答案(在您上面给出的链接中)并编辑 database.yml 以将您的生产数据库设置为相同作为开发数据库。通过这种方式,您还可以在生产环境中测试应用程序。在本地
  • @Uandl 我不太了解我必须做的事情。我编辑了主帖并添加了 database.yml 和我的 Gemfile。谢谢。
  • @Franky,我已经更新了我的答案。我假设您只想在本地测试生产环境。如果不是这种情况,请告诉我。并且不要忘记在测试后丢弃这些更改
  • 好的@Uandl,我已经像你告诉我的那样更改了database.yml 文件,我使用了rails s -e production 命令并且一切正常。但我想要将应用程序更新到heroku,客户端可以在生产模式下使用pg管理网站。我无法定期更新应用程序。
猜你喜欢
  • 2016-01-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-08
  • 1970-01-01
  • 2018-02-20
  • 2015-06-27
  • 1970-01-01
相关资源
最近更新 更多