# ActiveRecord::StatementInvalid NO\_GENERATED\_KEYS

**URL:** <https://www.ruby-forum.com/t/activerecord-statementinvalid-no-generated-keys/154357>\
**Category:** Rails\
**Created:** [November 28, 2008, 8:07am UTC](https://www.ruby-forum.com/t/activerecord-statementinvalid-no-generated-keys/154357 "2008-11-28T08:07:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![on9west](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/6f9a4e/32.png) [@on9west](https://www.ruby-forum.com/u/on9west)\
**Post date:** [November 28, 2008, 8:07am UTC](https://www.ruby-forum.com/t/activerecord-statementinvalid-no-generated-keys/154357/1 "2008-11-28T08:07:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![on9west](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/6f9a4e/32.png) [@on9west](https://www.ruby-forum.com/u/on9west)\
**Post date:** [November 28, 2008, 10:39am UTC](https://www.ruby-forum.com/t/activerecord-statementinvalid-no-generated-keys/154357/2 "2008-11-28T10:39:14Z")

</div>

On Nov 28, 7:07 am, Valentino L. [removed\_email\_address@domain.invalid](mailto: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
