Changes between Version 257 and Version 258 of BackwardsIncompatibleChanges


Ignore:
Timestamp:
Aug 28, 2008, 2:20:33 PM (16 years ago)
Author:
Malcolm Tredinnick
Comment:

Documented need for force_insert and force_update on save()

Legend:

Unmodified
Added
Removed
Modified
  • BackwardsIncompatibleChanges

    v257 v258  
    12771277== `create()` and `get_or_create()` will never update existing objects ==
    12781278
    1279 In [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.
     1279In [8670] a change was made to both `create()` and `get_or_create()` that affects people in two ways:
     1280
     1281'''Firstly''', if you have a custom `save()` method on your model and it is going to be called using `create()` or `get_or_create()`, you should make sure you accept the `force_insert` parameter (best to accept `force_update` as well, just like `django.db.models.base.Model.save()`). You don't have to do anything with these parameters, just pass them through to the `Model.save()` method.
     1282
     1283'''Secondly''', if you are 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.
    12801284
    12811285The 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.
Back to Top