#42 closed defect (fixed)
OneToOneField missing from DATA_TYPES dict
| Reported by: | Owned by: | Adrian Holovaty | |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | |
| Severity: | normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
revision 138 on trunk is missing entries for OneToOneField fields, and so sql generation fails if you have such a field in one of your models. below is a simple patch to add it to the backends.
Index: django/core/db/backends/postgresql.py
===================================================================
--- django/core/db/backends/postgresql.py (revision 134)
+++ django/core/db/backends/postgresql.py (working copy)
@@ -105,6 +105,7 @@
'IPAddressField': 'inet',
'ManyToManyField': None,
'NullBooleanField': 'boolean',
+ 'OneToOneField': None,
'PhoneNumberField': 'varchar(20)',
'PositiveIntegerField': 'integer CHECK (%(name)s >= 0)',
'PositiveSmallIntegerField': 'smallint CHECK (%(name)s >= 0)',
Index: django/core/db/backends/mysql.py
===================================================================
--- django/core/db/backends/mysql.py (revision 134)
+++ django/core/db/backends/mysql.py (working copy)
@@ -95,6 +95,7 @@
'IPAddressField': 'char(15)',
'ManyToManyField': None,
'NullBooleanField': 'bool',
+ 'OneToOneField': None,
'PhoneNumberField': 'varchar(20)',
'PositiveIntegerField': 'integer UNSIGNED',
'PositiveSmallIntegerField': 'smallint UNSIGNED',
the patch fixes sql generation for simple cases such as:
class Piece(meta.Model):
fields = (
meta.CharField('title', 'title', maxlength=256),
meta.DateTimeField('publishDate', 'date published'),
meta.ManyToManyField(Category),
)
class ImagePiece(meta.Model):
fields = (
meta.OneToOneField(Piece),
meta.FileField('data', 'data', upload_to='pieces'),
)
but more complicated models haven't been tested.
Attachments (1)
Change History (2)
by , 20 years ago
comment:1 by , 20 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Fixed in [156]. Thanks for reporting!