从rails 2升级到rails 3 ... sqlite3数据库不再有效

时间:2015-02-25 09:12:13

标签: ruby-on-rails sqlite rails-3-upgrade

我有一个Rails应用程序的代码,我正在从Rails 2.3.12更新到Rails 3.0.3。当它仍然是Rails 2.3.12时,我设法使数据库正常工作,但是由于我升级了Rails,它似乎“丢失”了表格,我无法弄清楚如何重新创建它们。

当我bundle exec rake db:create时,它表示测试和开发数据库已经存在。

然而,当我bundle exec rake db:migrate时,它说

rake aborted!
Could not find table 'comments'

所有迁移文件仍然存在,模式也是如此,但我不知道如何创建表?

修改

运行rake db:migrate --trace给了我这个:

** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
Could not find table 'comments'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activerecord-3.0.3/lib/active_record/connection_adapters/sqlite_adapter.rb:295:in `table_structure'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activerecord-3.0.3/lib/active_record/connection_adapters/sqlite_adapter.rb:186:in `columns'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activerecord-3.0.3/lib/active_record/base.rb:679:in `columns'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activerecord-3.0.3/lib/active_record/base.rb:692:in `column_names'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activerecord-3.0.3/lib/active_record/relation.rb:367:in `block in method_missing'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activerecord-3.0.3/lib/active_record/relation.rb:122:in `scoping'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activerecord-3.0.3/lib/active_record/relation.rb:367:in `method_missing'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rd_searchlogic-3.0.1/lib/searchlogic/named_scopes/conditions.rb:92:in `condition_details'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rd_searchlogic-3.0.1/lib/searchlogic/named_scopes/conditions.rb:68:in `local_condition?'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rd_searchlogic-3.0.1/lib/searchlogic/named_scopes/conditions.rb:61:in `condition?'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rd_searchlogic-3.0.1/lib/searchlogic/named_scopes/association_conditions.rb:6:in `condition?'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rd_searchlogic-3.0.1/lib/searchlogic/named_scopes/association_ordering.rb:14:in `condition?'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rd_searchlogic-3.0.1/lib/searchlogic/named_scopes/ordering.rb:11:in `condition?'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rd_searchlogic-3.0.1/lib/searchlogic/named_scopes/ordering.rb:31:in `order'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activerecord-3.0.3/lib/active_record/base.rb:441:in `order'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/acts_as_commentable-3.0.1/lib/comment_methods.rb:12:in `included'
/Users/camillavk/Documents/Work/Saild/saild/app/models/comment.rb:6:in `include'
/Users/camillavk/Documents/Work/Saild/saild/app/models/comment.rb:6:in `<class:Comment>'
/Users/camillavk/Documents/Work/Saild/saild/app/models/comment.rb:1:in `<top (required)>'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:454:in `load'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:454:in `block in load_file'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:596:in `new_constants_in'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:453:in `load_file'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:340:in `require_or_load'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:491:in `load_missing_constant'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:183:in `block in const_missing'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:181:in `each'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:181:in `const_missing'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/aws-s3-0.6.3/lib/aws/s3/extensions.rb:212:in `const_missing_from_s3_library'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.3/lib/active_support/inflector/methods.rb:124:in `block in constantize'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.3/lib/active_support/inflector/methods.rb:123:in `each'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.3/lib/active_support/inflector/methods.rb:123:in `constantize'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.3/lib/active_support/core_ext/string/inflections.rb:43:in `constantize'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activemodel-3.0.3/lib/active_model/observing.rb:182:in `observed_class'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activemodel-3.0.3/lib/active_model/observing.rb:175:in `observed_classes'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activemodel-3.0.3/lib/active_model/observing.rb:195:in `observed_classes'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activemodel-3.0.3/lib/active_model/observing.rb:191:in `initialize'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activerecord-3.0.3/lib/active_record/observer.rb:96:in `initialize'
/Users/camillavk/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/1.9.1/singleton.rb:141:in `new'
/Users/camillavk/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/1.9.1/singleton.rb:141:in `block in instance'
<internal:prelude>:10:in `synchronize'
/Users/camillavk/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/1.9.1/singleton.rb:139:in `instance'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activemodel-3.0.3/lib/active_model/observing.rb:66:in `instantiate_observer'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activemodel-3.0.3/lib/active_model/observing.rb:39:in `block in instantiate_observers'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activemodel-3.0.3/lib/active_model/observing.rb:39:in `each'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activemodel-3.0.3/lib/active_model/observing.rb:39:in `instantiate_observers'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activerecord-3.0.3/lib/active_record/railtie.rb:83:in `block (2 levels) in <class:Railtie>'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.3/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.3/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.3/lib/active_support/lazy_load_hooks.rb:26:in `on_load'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activerecord-3.0.3/lib/active_record/railtie.rb:82:in `block in <class:Railtie>'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.3/lib/active_support/lazy_load_hooks.rb:34:in `call'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.3/lib/active_support/lazy_load_hooks.rb:34:in `execute_hook'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.3/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.3/lib/active_support/lazy_load_hooks.rb:42:in `each'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.3/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/railties-3.0.3/lib/rails/application/finisher.rb:46:in `block in <module:Finisher>'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/railties-3.0.3/lib/rails/initializable.rb:25:in `instance_exec'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/railties-3.0.3/lib/rails/initializable.rb:25:in `run'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/railties-3.0.3/lib/rails/initializable.rb:50:in `block in run_initializers'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/railties-3.0.3/lib/rails/initializable.rb:49:in `each'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/railties-3.0.3/lib/rails/initializable.rb:49:in `run_initializers'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/railties-3.0.3/lib/rails/application.rb:134:in `initialize!'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/railties-3.0.3/lib/rails/application.rb:77:in `method_missing'
/Users/camillavk/Documents/Work/Saild/saild/config/environment.rb:7:in `<top (required)>'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `require'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `block in require'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `block in load_dependency'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:596:in `new_constants_in'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `load_dependency'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `require'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/railties-3.0.3/lib/rails/application.rb:103:in `require_environment!'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/railties-3.0.3/lib/rails/application.rb:216:in `block in initialize_tasks'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rake-0.8.7/lib/rake.rb:636:in `block in execute'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rake-0.8.7/lib/rake.rb:631:in `each'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rake-0.8.7/lib/rake.rb:597:in `block in invoke_with_call_chain'
/Users/camillavk/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rake-0.8.7/lib/rake.rb:607:in `block in invoke_prerequisites'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rake-0.8.7/lib/rake.rb:604:in `each'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rake-0.8.7/lib/rake.rb:604:in `invoke_prerequisites'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rake-0.8.7/lib/rake.rb:596:in `block in invoke_with_call_chain'
/Users/camillavk/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rake-0.8.7/lib/rake.rb:2029:in `block (2 levels) in top_level'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rake-0.8.7/lib/rake.rb:2029:in `block in top_level'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/airbrake-4.1.0/lib/airbrake/rake_handler.rb:43:in `standard_exception_handling'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rake-0.8.7/lib/rake.rb:2001:in `block in run'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/gems/rake-0.8.7/bin/rake:31:in `<top (required)>'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/bin/rake:23:in `load'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/bin/rake:23:in `<main>'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/bin/ruby_executable_hooks:15:in `eval'
/Users/camillavk/.rvm/gems/ruby-1.9.3-p551@rails3/bin/ruby_executable_hooks:15:in `<main>'

配置/ environment.rb中:

# Be sure to restart your server when you modify this file

# Load the rails application
require File.expand_path('../application', __FILE__)

#Initialize the rails application
Saild::Application.initialize!

评论模型:

class Comment < ActiveRecord::Base

  validates_presence_of :user
  validates_presence_of :commentable

  #include ActsAsCommentable::Comment

  acts_as_commentable

  belongs_to :commentable, :polymorphic => true
  has_many :feed_items, :as => :object, :dependent => :destroy

  default_scope order('created_at ASC')

  belongs_to :user

  def trip
    commentable.trip rescue false
  end

end

修改

我删除了以前破坏它的ActsAsCommentable,现在它在第13行(default_scope order ...)

0 个答案:

没有答案