Created
March 16, 2011 22:25
-
-
Save dcolebatch/873457 to your computer and use it in GitHub Desktop.
active record + arel's not playing nicely with SQLite3; suspect reflection issue after schema change
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I have a table called "tblPods" (legacy MSSQL server app... excuse it) with this schema: | |
-- Describe TBLPODS | |
CREATE TABLE tblpods ( | |
"ID" INTEGER(0), | |
"Name" VARCHAR(50) NOT NULL, | |
"Location" INTEGER(0) NOT NULL, | |
"Type" INTEGER(0), | |
"Production" BOOLEAN NOT NULL, | |
"MgmtNetworks" VARCHAR(50), | |
"Notes" VARCHAR(50) | |
) | |
When I alter table to turn ID into an auto incrementing PK I have this schema: | |
-- Describe TBLPODS | |
CREATE TABLE tblpods ( | |
"ID" INTEGER PRIMARY KEY, <--- Primary key now | |
"Name" VARCHAR(50) NOT NULL, | |
"Location" INTEGER(0) NOT NULL, | |
"Type" INTEGER(0), | |
"Production" BOOLEAN NOT NULL, | |
"MgmtNetworks" VARCHAR(50), | |
"Notes" VARCHAR(50) | |
) | |
If I make the change with rails console open, it all works perfectly. | |
irb(main):012:0> p = Pod.new; p.Name=Time.now.to_s; p.Location=2; p.Production=2; p.save | |
=> true | |
If I shutdown and relaunch rails console, I can no longer create new records: | |
irb(main):002:0> p = Pod.new; p.Name=Time.now.to_s; p.Location=2; p.Production=2; p.save | |
NoMethodError: undefined method `name' for nil:NilClass | |
from c:/bin/jruby-1.5.5/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/whiny_nil.rb:48:in `method_missing' | |
from c:/bin/jruby-1.5.5/lib/ruby/gems/1.8/gems/arel-2.0.9/lib/arel/visitors/to_sql.rb:57:in `visit_Arel_Nodes_InsertStatement' | |
from c:/bin/jruby-1.5.5/lib/ruby/gems/1.8/gems/arel-2.0.9/lib/arel/visitors/to_sql.rb:56:in `map' | |
from c:/bin/jruby-1.5.5/lib/ruby/gems/1.8/gems/arel-2.0.9/lib/arel/visitors/to_sql.rb:56:in `visit_Arel_Nodes_InsertStatement' | |
from c:/bin/jruby-1.5.5/lib/ruby/gems/1.8/gems/arel-2.0.9/lib/arel/visitors/visitor.rb:15:in `visit' | |
from c:/bin/jruby-1.5.5/lib/ruby/gems/1.8/gems/arel-2.0.9/lib/arel/visitors/visitor.rb:5:in `accept' | |
from c:/bin/jruby-1.5.5/lib/ruby/gems/1.8/gems/arel-2.0.9/lib/arel/visitors/to_sql.rb:19:in `accept' | |
from c:/bin/jruby-1.5.5/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:111:in `with_connection' | |
from c:/bin/jruby-1.5.5/lib/ruby/gems/1.8/gems/arel-2.0.9/lib/arel/visitors/to_sql.rb:17:in `accept' | |
from c:/bin/jruby-1.5.5/lib/ruby/gems/1.8/gems/arel-2.0.9/lib/arel/tree_manager.rb:20:in `to_sql' | |
from c:/bin/jruby-1.5.5/lib/ruby/gems/1.8/gems/arel-2.0.9/lib/arel/select_manager.rb:217:in `insert' | |
from c:0:in `insert' | |
from c:/bin/jruby-1.5.5/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/persistence.rb:270:in `create' | |
from c:/bin/jruby-1.5.5/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/timestamp.rb:47:in `create' | |
from c:/bin/jruby-1.5.5/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/callbacks.rb:281:in `create' | |
from c:/bin/jruby-1.5.5/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/callbacks.rb:428:in `_run_create_callbacks' | |
... 1 levels... | |
from c:/bin/jruby-1.5.5/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/persistence.rb:246:in `create_or_update' | |
from c:/bin/jruby-1.5.5/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/callbacks.rb:277:in `create_or_update' | |
from c:/bin/jruby-1.5.5/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/callbacks.rb:433:in `_run_save_callbacks' | |
from c:/bin/jruby-1.5.5/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/callbacks.rb:277:in `create_or_update' | |
from c:/bin/jruby-1.5.5/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/persistence.rb:39:in `save' | |
from c:/bin/jruby-1.5.5/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/validations.rb:43:in `save' | |
from c:/bin/jruby-1.5.5/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/attribute_methods/dirty.rb:21:in `save' | |
from c:/bin/jruby-1.5.5/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/transactions.rb:240:in `save' | |
from c:/bin/jruby-1.5.5/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/transactions.rb:292:in `with_transaction_returning_status' | |
from c:/bin/jruby-1.5.5/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction' | |
from c:/bin/jruby-1.5.5/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/transactions.rb:207:in `transaction' | |
from c:/bin/jruby-1.5.5/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/transactions.rb:290:in `with_transaction_returning_status' | |
from c:/bin/jruby-1.5.5/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/transactions.rb:240:in `save' | |
from c:/bin/jruby-1.5.5/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/transactions.rb:251:in `rollback_active_record_state!' | |
from c:/bin/jruby-1.5.5/lib/ruby/gems/1.8/gems/activerecord-3.0.5/lib/active_record/transactions.rb:239:in `save' | |
from (irb):2irb(main):003:0> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
By the way, this only happens on Windows... on linux, no problem.