Opened 19 years ago

Closed 19 years ago

Last modified 18 years ago

#42 closed defect (fixed)

OneToOneField missing from DATA_TYPES dict

Reported by: nullstyle@… 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)

db.patch (1.0 KB ) - added by nullstyle 19 years ago.

Download all attachments as: .zip

Change History (2)

by nullstyle, 19 years ago

Attachment: db.patch added

comment:1 by Adrian Holovaty, 19 years ago

Resolution: fixed
Status: newclosed

Fixed in [156]. Thanks for reporting!

Note: See TracTickets for help on using tickets.
Back to Top