我正在使用 rails 2.x 版本。我正在使用 mysql 5.0 数据库进行后端进程。当我执行以下步骤时,我遇到了迁移错误。
- 从 github 获取应用程序代码。
- 运行模式:创建、加载和种子过程
- 之后在应用程序中添加一些数据。
- 再次从同一分支中提取代码。
- 之后我运行 db:migrate 它会引发以下错误
-> rake db:migrate --trace DEPRECATION WARNING: Rake tasks in vendor/plugins/acts_as_audited/tasks,
vendor/plugins/annotate_models/tasks, vendor/plugins/app_version/tasks, vendor/plugins/bullet/tasks, vendor/plugins/importer/tasks, vendor/plugins/mimetype-fu/tasks, vendor/plugins/railsdav/tasks, vendor/plugins/rav/tasks、vendor/plugins/simple_captcha/tasks、vendor/plugins/smart_table/tasks、vendor/plugins/test_data_generator/tasks、vendor/plugins/visualize_models/tasks 和 vendor/plugins/xss_terminate/tasks 已弃用. 请改用 lib/tasks。(从 /usr/lib/ruby/gems/1.8/gems/rails-2.3.12/lib/tasks/rails.rb:10 调用)
** Invoke db:migrate (first_time) ** Invoke environment (first_time) ** Execute environmentThu 11 Jul 2013 09:24:36 AM IST ** Execute db:migrate == ConvertOrganizationToAwesomeNestedSet: migrating ========================== Running sample patched rebuild process. rake aborted! An error has occurred, all later migrations canceled: Validation failed: Name can't be blank /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.12/lib/active_record/validations.rb:1102:in
save_without_dirty!' /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.12/lib/active_record/dirty.rb:87:in
save_without_transactions!/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.12/lib/active_record/transactions.rb:200:insave!' /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.12/lib/active_record/connection_adapters/abstract/database_statements.rb:136:in
transaction' /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.12 /lib/active_record/transactions.rb:182:intransaction' /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.12/lib/active_record/transactions.rb:200:in
save!' /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.12/lib/active_record/transactions.rb:208:inrollback_active_record_state!' /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.12/lib/active_record/transactions.rb:200:in
save!' /opt/sample/lib/awesome_nested_set_overrides.rb:25:inrebuild!' /opt/sample/lib/awesome_nested_set_overrides.rb:22:in
call' /opt/sample/lib/awesome_nested_set_overrides.rb:22:inrebuild!' /opt/ssample/lib/awesome_nested_set_overrides.rb:22:in
each' /opt/sample/lib/awesome_nested_set_overrides.rb:22:inrebuild!' /opt/sample/lib/awesome_nested_set_overrides.rb:32:in
call' /opt /sample/lib/awesome_nested_set_overrides.rb:32:inrebuild!' /opt/sample/lib/awesome_nested_set_overrides.rb:29:in
each' /opt/sample/lib/awesome_nested_set_overrides.rb:29:inrebuild!' ./db/migrate//20130102220216_convert_organization_to_awesome_nested_set.rb:6:in
up_without_benchmarks' /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.12/lib/active_record/migration.rb:282:insend' /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.12/lib/active_record/migration.rb:282:in
迁移' /usr/lib/ruby/1.8/benchmark.rb:293:inmeasure' /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.12/lib/active_record/migration.rb:282:in
迁移'/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.12/lib/active_record/migration.rb:365:in__send__' /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.12/lib/active_record/migration.rb:365:in
迁移'/usr/lib/ruby/gems/1.8/gems/activerecord-2.3 .12/lib/active_record/migration.rb:491:inmigrate' /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.12/lib/active_record/migration.rb:567:in
call' /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.12/lib/active_record/migration.rb:567:inddl_transaction' /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.12/lib/active_record/migration.rb:490:in
migrate' /usr /lib/ruby/gems/1.8/gems/activerecord-2.3.12/lib/active_record/migration.rb:477:ineach' /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.12/lib/active_record/migration.rb:477:in
migrate' /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.12/lib /active_record/migration.rb:401:inup' /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.12/lib/active_record/migration.rb:383:in
迁移' /usr/lib/ruby/gems/1.8/gems/rails-2.3.12/lib/tasks/databases.rake:112 /usr/lib/ruby/gems/1.8/gems/rake-10.0.3/lib /rake/task.rb:228:incall' /usr/lib/ruby/gems/1.8/gems/rake-10.0.3/lib/rake/task.rb:228:in
执行'/usr/lib/ruby/gems/1.8/gems/rake-10.0.3/lib/rake/task.rb:223:ineach' /usr/lib/ruby/gems/1.8/gems/rake-10.0.3/lib/rake/task.rb:223:in
执行'/usr/lib/ruby /gems/1.8/gems/rake-10.0.3/lib/rake/task.rb:166:ininvoke_with_call_chain' /usr/lib/ruby/1.8/monitor.rb:242:in
synchronize' /usr/lib/ruby/gems/1.8/gems/rake-10.0.3/lib/rake/task .rb:159:ininvoke_with_call_chain' /usr/lib/ruby/gems/1.8/gems/rake-10.0.3/lib/rake/task.rb:152:in
调用'/usr/lib/ruby/gems/1.8/gems/rake-10.0.3/lib/rake/application.rb:143:ininvoke_task' /usr/lib/ruby/gems/1.8/gems/rake-10.0.3/lib/rake/application.rb:101:in
top_level'/usr/lib/ruby/gems/1.8 /gems/rake-10.0.3/lib/rake/application.rb:101:ineach' /usr/lib/ruby/gems/1.8/gems/rake-10.0.3/lib/rake/application.rb:101:in
top_level' /usr/lib/ruby/gems/1.8/gems/rake-10.0.3/lib/rake/application.rb:110 :在run_with_threads' /usr/lib/ruby/gems/1.8/gems/rake-10.0.3/lib/rake/application.rb:95:in
顶层'/usr/lib/ruby/gems/1.8/gems/rake-10.0.3/lib/rake/application.rb: 73:在run' /usr/lib/ruby/gems/1.8/gems/rake-10.0.3/lib/rake/application.rb:160:in
standard_exception_handling' /usr/lib/ruby/gems/1.8/gems/rake-10.0.3/lib/rake/application.rb:70:inrun' /usr/lib/ruby/gems/1.8/gems/rake-10.0.3/bin/rake:33 /usr/bin/rake:19:in
load' /usr/bin/rake:19 任务:TOP => db:migrate
Organization.rebuild!
- 这是调用插件的代码。
awesome_nested_set 插件似乎有一些问题。在过去的一周里,我一直在为此苦苦挣扎。任何意见将不胜感激。
编辑 - 1
class ConvertOrganizationToAwesomeNestedSet < ActiveRecord::Migration
def self.up
# add_column :party, :lft, :integer
# add_column :party, :rgt, :integer
Organization.reset_column_information
Organization.rebuild!
end
def self.down
remove_column :party, :lft
remove_column :party, :rgt
end
end
模型 - 组织
class Organization < Party
attr_accessible :name,
:parent_id
default_scope :order => 'name'
acts_as_nested_set has_many :children, :class_name => 'Organization',
:foreign_key => "parent_id"
belongs_to :parent, :class_name =>'Organization', :foreign_key => "parent_id"
def display_name
name
end