ActiveRecord::StatementInvalid NO_GENERATED_KEYS


#1

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:insave_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:insignal_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:ineval_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:incatch’
from C:/jruby-1.1.5/lib/ruby/1.8/irb.rb:69:in `start’
from C:/jruby-1.1.5\bin\jirb:21


#2

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