integrity error Date field auto_now_add for RelatedKey field object data (edit_inline)
|Reported by:||alex@…||Owned by:||nobody|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I also stepped to problem similar to ticket:3156 (but this bug is another branch, also problem only looks similar, but patch is different)
I have Order, and related model GoogleOrderInformation which I want to see/edit inline.
Here is related part of model code:
class GoogleOrderInformation(models.Model): order = models.ForeignKey(Order,edit_inline=models.STACKED,max_num_in_admin=1) google_order_number = models.CharField(maxlength=40) .... added = models.DateTimeField(auto_now_add = True) changed = models.DateTimeField(auto_now = True) ...
When I hit "save" button in Django oldforms admin, I get this error:
Exception Type: IntegrityError Exception Value: null value in column "added" violates not-null constraint
And the actual SQL code at the bottom shows me this:
'UPDATE "GoogleCheckout_googleorderinformation" SET "order_id"=\'8314\',"google_order_number"=\'das\',"added"=NULL,"changed"=\'2007-11-30 16:29:26.995612\',"eligible_for_protection"=true,"avs_response"=\'f\',"cvn_response"=\'f\',"partial_cc_number"=\'sfsd\',"buyer_account_age"=NULL,"timestamp"=\'2007-11-30 18:18:09\' WHERE "id"=\'2\''
I've looked at actual manipulators code (btw not easy to read/understand) and patched it quickly.
I would like to share this patch with Django community, so anyone else encountering same problem will be able to patch it.
Attached is patch, as it works for me. No guarantees that it works for you.
I did not made tests, neither I tested it for MySQL or SQLlite. That is because I've been told a number of times that all patches to oldforms admin
are not useful, and will be refused anyway, so I don't want to spend much of my time on this. Just use patch if it fixes your problem, and lets
hope all for a quicker release of newforms-admin.
Change History (4)
Changed 7 years ago by alex@…
comment:1 Changed 7 years ago by MichaelBishop
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Resolution set to wontfix
- Status changed from new to closed