Raf Andersson Wed Aug 14 17:07:36 -0400 2013

Subject: creation with validates_uniqueness_of on primary key error

(please somebody make a search inside this forum)

There is a problem when using validates_uniqueness_of on the primary key

Database table members:
number int primary key
name varchar 255

php version 5.4.10
mysql version 5.5.29

I use this in my model:
static $validates_uniqueness_of = array(
array('number', 'message' => 'custom message', 'on' => 'create')
);

and then just do a simple create like this, where attributes is a name and a number, and the primary key:
$member = Member::create($attributes);

The error I get is not my custom message but:
Internal Server Error: 23000, 1062, Duplicate entry '3' for key 'PRIMARY'
(code 500 I believe)

then what is the point of validates_uniqueness_of if it doesn't work?

Raf