This project is archived and is in readonly mode.
Delete me
-
ronin-68998 (at lighthouseapp)
Found the issue:
This should at least raise a warning or be documented that you're doing something silly or non-conventional.
Bug:
Given the following migration you'll notice two columns with :null => false, in the following model 'Broken' you'll notice one validates_presence_of.
If you run the following code:
Broken.create({:first_name => 'Test', :last_name => 'User'}) => PGError: ERROR: null value in column "first_name" violates not-null constraint Works.create({:first_name => 'Test', :last_name => 'User'}) => YAY:last_name is ignored before insert because it's not in the validator chain, that's clearly undocument or faulty behavor for postgresql, even though the value for :last_name was passed.
class CreateUsers < ActiveRecord::Migration def self.up create_table :users do |t| # names! t.string :first_name, :null => false t.string :last_name, :null => false t.timestamps end end def self.down drop_table :users end end class Works < ActiveRecord::Base set_table_name 'users' validates_presence_of :first_name, :on => :create validates_presence_of :last_name, :on => :create end class Broken < ActiveRecord::Base set_table_name 'users' validates_presence_of :first_name, :on => :create end -
ronin-68998 (at lighthouseapp)
- Title changed from ActiveRecord create on Postgres induces not-null constrains to Delete me
-
Rohit Arondekar
- State changed from new to invalid
- Importance changed from to Low