Dear all I type the following command in script/console and got the error "ActiveRecord::StatementInvalid: ActiveRecord::ActiveRecordError: JZ0NK: ......Statement.NO_GENERATED_KEYS" It is quit strange that the title is nil when I saved the record....This problem only happened in the rails console. It is no problem in my irb. Please help me. Thank you.>> user=> #<User name: "aaa", title: nil, created_at: "2008-11-28 07:02:26", updated_at: "2008-11-28 07:02: 26">>> user = User.new=> #<User name: nil, title: nil, created_at: nil, updated_at: nil>>> User=> User(name: string, title: string, created_at: datetime, updated_at: datetime)>> user=User.new=> #<User name: nil, title: nil, created_at: nil, updated_at: nil>>> user.name = "aaaaa"=> "aaaaa">> user.title = "bbbbb"=> "bbbbb">> user=> #<User name: "aaaaa", title: nil, created_at: nil, updated_at: nil>>> user.saveActiveRecord::StatementInvalid: ActiveRecord::ActiveRecordError: JZ0NK: ???銝?剁? ?蛹雿輻鈭?Statement.NO_GENERATED_KEYS ?僎?芾?函???? INSERT INTO users (title, created_at , updated_at, name) VALUES(NULL, ''2008-11-28 07:04:11'', ''2008-11-28 07:04:11'', ''aaaaa'') from C:/jruby-1.1.5/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions .rb:167:in `rollback_active_record_state!'' from C:/jruby-1.1.5/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions .rb:146:in `save_with_transactions'' from (irb):16 from C:/jruby-1.1.5/lib/ruby/1.8/irb.rb:150:in `eval_input'' from C:/jruby-1.1.5/lib/ruby/1.8/irb.rb:259:in `signal_status'' from C:/jruby-1.1.5/lib/ruby/1.8/irb.rb:147:in `eval_input'' from C:/jruby-1.1.5/lib/ruby/1.8/irb.rb:146:in `eval_input'' from C:/jruby-1.1.5/lib/ruby/1.8/irb.rb:70:in `start'' from C:/jruby-1.1.5/lib/ruby/1.8/irb.rb:69:in `catch'' from C:/jruby-1.1.5/lib/ruby/1.8/irb.rb:69:in `start'' from C:/jruby-1.1.5\bin\jirb:21 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Nov-28 09:38 UTC
Re: ActiveRecord::StatementInvalid NO_GENERATED_KEYS
On Nov 28, 7:07 am, Valentino Lun <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Dear all > > I type the following command in script/console and got the error > "ActiveRecord::StatementInvalid: ActiveRecord::ActiveRecordError: JZ0NK: > ......Statement.NO_GENERATED_KEYS" > > It is quit strange that the title is nil when I saved the record....This > problem only happened in the rails console. It is no problem in my irb. > Please help me. Thank you. >Your attr_accessor :title is messing things up. You do not need that for attributes defined in the database. Furthermore attributes are not stored in instance variables so doing @title = ''foo'' is a waste of time Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---