Is there a way to identify why the database ROLLSBACK in a Rails application?
I'm trying to update a model object, and it keeps rolling back. Occassionaly protesting that it is a validation error. But it doesn't point to what is actually failing.
In the end, I tried to delete it, but in the deletion, it still fails validation.
Is there a way to debug this and find out exactly why/what is causing this?
Thanks
A typical response to an update or delete:
ActiveRecord::RecordNotSaved: ActiveRecord::RecordNotSaved
from /data/HQ_Channel2/releases/201开发者_高级运维11011173855/vendor/rails/activerecord/lib/active_record/base.rb:2551:in `save_without_validation!'
from /data/HQ_Channel2/releases/20111011173855/vendor/rails/activerecord/lib/active_record/validations.rb:1019:in `save_without_dirty!'
from /data/HQ_Channel2/releases/20111011173855/vendor/rails/activerecord/lib/active_record/dirty.rb:87:in `save_without_transactions!'
from /data/HQ_Channel2/releases/20111011173855/vendor/rails/activerecord/lib/active_record/transactions.rb:200:in `save!'
from /data/HQ_Channel2/releases/20111011173855/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:136:in `transaction'
And for more evidence, this is the stack from the appication when I try to create a new object:
Processing OrganizationsController#create (for 127.0.0.1 at 2011-10-12 15:43:02) [POST]
Parameters: {"commit"=>"submit", "action"=>"create", "authenticity_token"=>"QxTT80hdtULmkt7PeUH5MG+BZ/5l+a22ry3EL49q1V8=", "controller"=>"organizations", "organization"=>{"city"=>"lkjlkj", "name"=>"asdfa", "contact_24"=>"1", "zip"=>"123123", "quick_description"=>"2342, 123, 3,2423, 2", "url"=>"www.martini494bistro.com/", "hq_url"=>"12341234", "map_it"=>"1", "street"=>"lkjlkj", "phone_work"=>"123123123123", "is_authorized"=>"1", "state"=>"NJ"}}
User Columns (2.2ms) SHOW FIELDS FROM `users`
User Load (4.4ms) SELECT * FROM `users` WHERE (`users`.`persistence_token` = '77ca6dea2961c5102be62d8e995e3f4bfdcb5bcfdf64a4e8361d2f3b49e9b377e6467d1a01a3fbe7fc6dab76382220b044d3782f6045130a2de047d8b8f0bd87') LIMIT 1
SQL (0.1ms) BEGIN
User Update (0.3ms) UPDATE `users` SET `updated_at` = '2011-10-12 19:43:02', `perishable_token` = 'YP8Ivses9OgR6LtrNBvF', `last_request_at` = '2011-10-12 19:43:02' WHERE `id` = 2953
Solr Update (7.0ms) <?xml version="1.0" encoding="UTF-8"?><add><doc><field name="type">User</field><field name="type">ActiveRecord::Base</field><field name="id">User 2953</field><field name="email_s">asdfasdf@asdfasdf.com</field><field name="name_s">asdfadsf adfasdf</field><field name="first_name_s">asdfadsf</field><field name="created_at_d">2011-10-12T19:39:36Z</field><field name="class_name">User</field><field name="last_name_s">adfasdf</field><field name="name_text">asdfadsf adfasdf</field><field name="email_text">asdfasdf@asdfasdf.com</field><field name="last_name_text">adfasdf</field><field name="first_name_text">asdfadsf</field></doc></add>
SQL (0.6ms) COMMIT
SQL (1.1ms) SHOW TABLES
Organization Columns (5.4ms) SHOW FIELDS FROM `organizations`
Organization Load (2.9ms) SELECT `organizations`.* FROM `organizations` INNER JOIN `organizations_users` ON `organizations`.id = `organizations_users`.organization_id WHERE ((`organizations_users`.user_id = 2953))
SQL (0.1ms) BEGIN
Organization Load (1.1ms) SELECT `organizations`.id FROM `organizations` WHERE (LOWER(`organizations`.`name`) = BINARY 'asdfa') LIMIT 1
Organization Load (2.2ms) SELECT `organizations`.id FROM `organizations` WHERE (LOWER(`organizations`.`hq_url`) = BINARY '12341234') LIMIT 1
QuickFact Columns (1.3ms) SHOW FIELDS FROM `quick_facts`
SQL (2.2ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
SQL (0.1ms) ROLLBACK
SQL (3.1ms) BEGIN
CACHE (0.0ms) SELECT `organizations`.id FROM `organizations` WHERE (LOWER(`organizations`.`name`) = BINARY 'asdfa') LIMIT 1
CACHE (0.0ms) SELECT `organizations`.id FROM `organizations` WHERE (LOWER(`organizations`.`hq_url`) = BINARY '12341234') LIMIT 1
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
SQL (0.1ms) ROLLBACK
CACHE (0.0ms) SELECT `organizations`.id FROM `organizations` WHERE (LOWER(`organizations`.`name`) = BINARY 'asdfa') LIMIT 1
CACHE (0.0ms) SELECT `organizations`.id FROM `organizations` WHERE (LOWER(`organizations`.`hq_url`) = BINARY '12341234') LIMIT 1
SQL (0.1ms) BEGIN
CACHE (0.0ms) SELECT `organizations`.id FROM `organizations` WHERE (LOWER(`organizations`.`name`) = BINARY 'asdfa') LIMIT 1
CACHE (0.0ms) SELECT `organizations`.id FROM `organizations` WHERE (LOWER(`organizations`.`hq_url`) = BINARY '12341234') LIMIT 1
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
SQL (0.1ms) ROLLBACK
SQL (0.1ms) BEGIN
CACHE (0.0ms) SELECT `organizations`.id FROM `organizations` WHERE (LOWER(`organizations`.`name`) = BINARY 'asdfa') LIMIT 1
CACHE (0.0ms) SELECT `organizations`.id FROM `organizations` WHERE (LOWER(`organizations`.`hq_url`) = BINARY '12341234') LIMIT 1
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
SQL (0.1ms) ROLLBACK
Rendering template within layouts/application
Rendering organizations/new
Rendered organizations/_form (4.2ms)
Rendered layouts/_head (2.7ms)
SQL (0.7ms) SELECT count(*) AS count_all FROM `organizations` INNER JOIN `organizations_users` ON `organizations`.id = `organizations_users`.organization_id WHERE ((`organizations_users`.user_id = 2953))
Rendered layouts/_login_status_new (2.1ms)
Rendered layouts/_header_new (2.9ms)
Rendered layouts/_need_login (0.2ms)
Rendered layouts/_already_have_tooltip (0.1ms)
Completed in 227923ms (View: 34, DB: 29) | 200 OK [http://localhost/organizations]
SQL (0.1ms) SET NAMES 'utf8'
SQL (0.1ms) SET NAMES 'utf8'
SQL (0.1ms) SET SQL_AUTO_IS_NULL=0
Processing DynamicStylesheetsController#image_css to css (for 127.0.0.1 at 2011-10-12 15:46:50) [GET]
Parameters: {"format"=>"css", "action"=>"image_css", "controller"=>"dynamic_stylesheets"}
At a guess, these lines:
SQL (2.2ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
CACHE (0.0ms) SELECT count(*) AS count_all FROM `quick_facts` WHERE (`quick_facts`.organization_id = NULL)
SQL (0.1ms) ROLLBACK
.. mean that you have a uniqueness validation that's failing because the null value is "taken".
精彩评论