Django

Code

Ticket #5102 (closed: fixed)

Opened 1 year ago

Last modified 1 year ago

Allow zero pk inserts in post_syncdb

Reported by: oggie rob <oz.robharvey@gmail.com> Assigned to: adrian
Milestone: Component: Core framework
Version: SVN Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

In setting up a database, it is nice to allow for pk=0 objects in the database (specifically to deal with non-null foreign keys). Because of indexes, this is possible only when post_syncdb is triggered (and not via fixtures), but since it is a logical data entry it makes sense to allow code entries for it. For example:

        User.objects.create(id=0, username='', first_name='', last_name='', email='', password='', is_active=False, is_staff=False,
            is_superuser=False, date_joined=datetime(1900,1,1), last_login=datetime(1900,1,1))

However one line prevents this by using bool(pk_val), which is the same for pk_val is None and pk_val = 0. The patch fixes this and allows for post_syncdb additions of zero pk inserts.

Attachments

zero_pk.diff (0.6 kB) - added by oggie rob <oz.robharvey@gmail.com on 08/06/07 13:59:10.
One-liner diff to use "is not None" instead of "bool"

Change History

08/06/07 13:59:10 changed by oggie rob <oz.robharvey@gmail.com

  • attachment zero_pk.diff added.

One-liner diff to use "is not None" instead of "bool"

08/12/07 05:12:34 changed by Simon G. <dev@simon.net.nz>

  • needs_better_patch changed.
  • stage changed from Unreviewed to Ready for checkin.
  • summary changed from [patch] Allow zero pk inserts in post_syncdb to Allow zero pk inserts in post_syncdb.
  • needs_tests changed.
  • needs_docs changed.

08/18/07 02:40:59 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

(In [5933]) Fixed #5102 -- Fixed model saving so that 0 can be used as a primary key value. Thanks, oggie rob.

08/18/07 22:23:32 changed by mtredinnick

(In [5934]) Tweaked the unset primary key check from [5933] to accommodate models created in the oldforms style. It's a backwards-compatibility hack that we can remove when oldforms go away. See #2160 for discussion. Fixed #5204, #2160. Refs #5102.


Add/Change #5102 (Allow zero pk inserts in post_syncdb)




Change Properties
Action