I am doing this
CasPgtiou.create({:pgt_iou => "a", :pgt_id => "b"})
which results in
INSERT INTO `cas_pgtious` (`created_at`, `pgt_id`, `pgt_iou`, `updated_at`) VALUES ('2015-06-25 02:22:55', NULL, NULL, '2015-06-25 02:22:55')
Mysql2::Error: Column 'pgt_id' cannot be null: INSERT INTO `cas_pgtious` (`created_at`, `pgt_id`, `pgt_iou`, `updated_at`) VALUES ('2015-06-25 02:22:55', NULL, NULL, '2015-06-25 02:22:55')
ActiveRecord::StatementInvalid: Mysql2::Error: Column 'pgt_id' cannot be null: INSERT INTO `cas_pgtious` (`created_at`, `pgt_id`, `pgt_iou`, `updated_at`) VALUES ('2015-06-25 02:22:55', NULL, NULL, '2015-06-25 02:22:55')
Even though the value is there the create function is not taking it. Also the model I have is like this
class CasPgtiou < ActiveRecord::Base
attr_accessible :pgt_iou, :pgt_id
end
Rails version is 3.1.3. I'm not sure why a thing as simple as this would fail.
PS I have tried create this way also. But same error
CasPgtiou.create(:pgt_iou => "a", :pgt_id => "b")
UPDATE
This thing strangely works
pgtiou = CasPgtiou.new
pgtiou[:pgt_iou] = pgt_iou
pgtiou[:pgt_id] = pgt
pgtiou.save!
Aucun commentaire:
Enregistrer un commentaire