Ticket #578 (closed defect: fixed)
Boolean default values are not set correctly when adding new columns with sqlite
|Reported by:||luper.rouch@…||Owned by:||andrew|
If you add a new BooleanField to a model, with default=True in a SQLite database, the column will be filled with 'True' strings after migration, and that won't be interpreted as True booleans in Django.
This is because SQLite doesn't have a boolean type, and Django expects booleans to be stored as '1' or '0' in SQLite databases. The problem is specific to SQLite, other database backends recognize "DEFAULT True" properly as a boolean value.
To fix this we need some sort of database-specific mechanism to transform Python values to their SQL representation. Attached is a patch with a suggestion of API to do this properly, and the fix for this particular SQLite problem.
Note: the patch also uses django's Field.get_db_prep_save() method to transform the default values to their database representation, which I believe is the correct way to process values before passing them to the database layer.
- Status changed from new to accepted
- Milestone changed from 0.7.3 to 1.0
- Status changed from accepted to closed
- Resolution set to fixed
comment:10 Changed 7 months ago by Michel van Leeuwen <michel@…>
- Status changed from closed to reopened
- Resolution fixed deleted