I temporily add an extra line before "is :tree" : property :parent_id, Integer
That is ok but looks ugly. On Oct 2, 8:02 am, sliu <[email protected]> wrote: > See the following code: > > class A > include DataMapper::Resource > property :id, Serial > > is :tree > end > > A.auto_migrate! > > A.new.save! > > The last line will raise exception: > > /usr/local/ruby/lib/ruby/gems/1.8/gems/dm-core-0.10.1/lib/dm-core/ > adapters/data_objects_adapter.rb:162:in `execute_non_query': Field > 'parent_id' doesn't have a default value (DataObjects::SQLError) > from /usr/local/ruby/lib/ruby/gems/1.8/gems/dm-core-0.10.1/lib/dm- > core/adapters/data_objects_adapter.rb:162:in `execute' > from /usr/local/ruby/lib/ruby/gems/1.8/gems/dm-core-0.10.1/lib/dm- > core/adapters/data_objects_adapter.rb:266:in `with_connection' > from /usr/local/ruby/lib/ruby/gems/1.8/gems/dm-core-0.10.1/lib/dm- > core/adapters/data_objects_adapter.rb:160:in `execute' > from /usr/local/ruby/lib/ruby/gems/1.8/gems/dm-core-0.10.1/lib/dm- > core/adapters/data_objects_adapter.rb:58:in `create' > from /usr/local/ruby/lib/ruby/gems/1.8/gems/dm-core-0.10.1/lib/dm- > core/adapters/data_objects_adapter.rb:31:in `each' > from /usr/local/ruby/lib/ruby/gems/1.8/gems/dm-core-0.10.1/lib/dm- > core/adapters/data_objects_adapter.rb:31:in `create' > from /usr/local/ruby/lib/ruby/gems/1.8/gems/dm-core-0.10.1/lib/dm- > core/repository.rb:125:in `create' > from /usr/local/ruby/lib/ruby/gems/1.8/gems/dm-core-0.10.1/lib/dm- > core/resource.rb:808:in `_create' > from /usr/local/ruby/lib/ruby/gems/1.8/gems/dm-core-0.10.1/lib/dm- > core/resource.rb:556:in `save_self' > from /usr/local/ruby/lib/ruby/gems/1.8/gems/dm-validations-0.10.1/lib/ > dm-validations.rb:55:in `save_self' > from /usr/local/ruby/lib/ruby/gems/1.8/gems/dm-core-0.10.1/lib/dm- > core/resource.rb:354:in `save!' > > This is because auto_migration generate `parent_id` column with NOT > NULL option, and when I add a root node(parent_id is null), database > won't pass. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "DataMapper" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/datamapper?hl=en -~----------~----~----~----~------~----~------~--~---
