Rails migration error - Name can't be blank -
i using rails 2.x version. using mysql 5.0 database end process. faced migration error when did following steps.
- get application code github.
- run schema:create, load , seed process
- after add data in application.
- again pull code same branch.
- after run db:migrate throws following error
-> 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 deprecated. use lib/tasks instead. (called /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 ist ** execute db:migrate == convertorganizationtoawesomenestedset: migrating ========================== running sample patched rebuild process. rake aborted! error has occurred, later migrations canceled: validation failed: name can't 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
migrate' /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
migrate' /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
migrate' /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
execute' /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
execute' /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
invoke' /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
load' /usr/bin/rake:19 tasks: top => db:migrate
organization.rebuild!
- code calls plugin.
it seems there problem awesome_nested_set plugin. struggle past 1 week. comments appreciated.
edit - 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
model - organization
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
you using activerecord model class in migration. in short: don't.
this cause problems in long run. if have migration uses model class, , run again later on, you'll in trouble if changes model class.
migrations strictly setting database, , should constructed behave in same way - regardless of current state of app's code is.
if need migration activerecord model: define class inside migration file. way immutable changes rest of app.
Comments
Post a Comment