Django: Ticket Queryhttps://code.djangoproject.com/query?status=!closed&reporter=emyller&order=priority
The Web framework for perfectionists with deadlines.en-USDjangohttps://www.djangoproject.com/s/img/site/hdr_logo.gifhttps://code.djangoproject.com/query?status=!closed&reporter=emyller&order=priority
Trac 1.2https://code.djangoproject.com/ticket/24539
https://code.djangoproject.com/ticket/24539#24539: Attempt to create object with repeated value on a custom PK raises IntegrityError on wrong fieldThu, 26 Mar 2015 05:17:40 GMTEvandro Myller<p>
I have this model <code>Product</code>, child of an abstract model which defines a <code>created</code> field with <code>auto_now_add</code> set. All the CRUD works just fine so far.
</p>
<p>
The problem happens when I add a custom primary key to <code>Product</code>: If I try to <strong>create</strong> a <code>Product</code> object through the admin giving the <code>reference</code> field a repeated value, expecting to see a nice validation error message saying that another object with that reference already exists, I get an <code>IntegrityError</code> stating that the <code>created</code> field cannot be <code>NULL</code> (traceback attached) -- nothing even about the custom primary key.
</p>
<p>
Notes:
</p>
<ul><li>I noticed the exception is raised from an <code>UPDATE</code> query, which is really odd since I'm posting data from the admin add view.
</li><li><code>Product(reference=x).save()</code> raises the same exception, but <code>Product.objects.create(reference=x</code> raises the expected exception (<code>IntegrityError</code> about the PK's UNIQUE constraint), which proves that it's not a problem on the admin.
</li></ul>Resultshttps://code.djangoproject.com/ticket/24539#changelog