我正在使用rails 2.x版本。我使用mysql 5.0数据库进行后端处理。当我执行以下步骤时,我遇到了迁移错误。
-> rake db:migrate --trace DEPRECATION WARNING: Rake tasks in vendor/plugins/acts_as_audited/tasks,
供应商/插件/ annotate_models /任务, 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, 供应商/插件/ test_data_generator /任务, 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
交易” /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
救人!” /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
救人!” /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
每个' /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
每个' /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
migrate' /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
称之为” /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
迁移” /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
迁移” /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:inrun_with_threads' /usr/lib/ruby/gems/1.8/gems/rake-10.0.3/lib/rake/application.rb:95:in
TOP_LEVEL” /usr/lib/ruby/gems/1.8/gems/rake-10.0.3/lib/rake/application.rb:73:inrun' /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
负载” 在/ usr / bin中/耙:19 任务:TOP =>分贝:迁移
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
答案 0 :(得分:1)
您正在迁移中使用ActiveRecord模型类。简而言之:不要。
从长远来看,这可能会导致问题。如果您有一个使用模型类的迁移,而不是稍后再次运行它,那么如果有人更改了该模型类,您将遇到麻烦。
迁移严格用于设置数据库,并且应该构建为使它们始终以相同的方式运行 - 无论应用程序代码的当前状态如何。
如果您确实需要迁移到ActiveRecord模型:在迁移文件中定义该类。这样,对应用程序的其余部分进行更改将是不可变的。
答案 1 :(得分:0)
因为你正在
Validation failed: Name can't be blank
你必须有一个
validates_presence_of :name
某个地方,无论是在你的班级还是在插件中。
也许您的数据库中有一些无效的记录,当您重建时,它们会被保存(并经过验证),并且您会收到此错误。