Code

Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#42 closed defect (fixed)

OneToOneField missing from DATA_TYPES dict

Reported by: nullstyle@… Owned by: adrian
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: UI/UX:

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 9 years ago.

Download all attachments as: .zip

Change History (2)

Changed 9 years ago by nullstyle

comment:1 Changed 9 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

Fixed in [156]. Thanks for reporting!

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.