Forum: Ruby on Rails ActiveRecord::StatementInvalid NO_GENERATED_KEYS

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Valentino L. (Guest)
on 2008-11-28 09:07
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.save
ActiveRecord::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
Frederick C. (Guest)
on 2008-11-28 11:39
(Received via mailing list)
On Nov 28, 7:07 am, Valentino L. <removed_email_address@domain.invalid>
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
This topic is locked and can not be replied to.