Changes between Version 256 and Version 257 of BackwardsIncompatibleChanges


Ignore:
Timestamp:
08/28/2008 12:22:46 PM (7 years ago)
Author:
mtredinnick
Comment:

Documented changes to create() and get_or_create()

Legend:

Unmodified
Added
Removed
Modified
  • BackwardsIncompatibleChanges

    v256 v257  
    12741274myform['foo']      # Has always worked. Works for Forms and ModelForms.
    12751275}}}
     1276
     1277== `create()` and `get_or_create()` will never update existing objects ==
     1278
     1279In [8670] a change was made to both `create()` and `get_or_create()` that affects people using manually specific primary keys on their models. There are two possible interpretations of what might happen if the key you passed into these functions already exists (in the case where the objects didn't already exist in the `get_or_create()` method). The previous behaviour was that, after the call returned, the data you passed in would always exist in the database and the object (and object with those values was always brought into existence). The side-effect here was that any existing row in the database with that primary key value was updated and this might have been unintended.
     1280
     1281The new behaviour is that these two methods will always create a new row in the database. If a row with that primary key value already exists, an exception is raised.
     1282
     1283For most people, this change will have no effect. It is only relevant if you are using custom primary key attributes and relying on the old behaviour as a way of keeping the data up to date if older values previously existed. You will now have to emulate that old behaviour manually (by calling `save()` on the model instance).
Back to Top