File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change 1
1
Changes
2
2
=======
3
3
4
+ tip (unreleased)
5
+ ----------------
6
+ - Fix OneToOneField transformation for historical models (gh-166)
7
+
4
8
1.6.0 (2015-04-16)
5
9
------------------
6
10
- Add support for Django 1.8+
Original file line number Diff line number Diff line change 4
4
import copy
5
5
import warnings
6
6
7
+ import django
7
8
from django .db import models , router
8
9
from django .db .models import loading
9
10
from django .db .models .fields .proxy import OrderWrt
@@ -129,18 +130,26 @@ def copy_fields(self, model):
129
130
field .__class__ = models .IntegerField
130
131
if isinstance (field , models .ForeignKey ):
131
132
old_field = field
132
- field = type (field )(
133
- field .rel .to ,
133
+ field_arguments = {}
134
+ if (getattr (old_field , 'one_to_one' , False ) or
135
+ isinstance (old_field , models .OneToOneField )):
136
+ FieldType = models .ForeignKey
137
+ else :
138
+ FieldType = type (old_field )
139
+ if django .get_version () >= "1.6" :
140
+ field_arguments ['db_constraint' ] = False
141
+ field = FieldType (
142
+ old_field .rel .to ,
134
143
related_name = '+' ,
135
144
null = True ,
136
145
blank = True ,
137
146
primary_key = False ,
138
147
db_index = True ,
139
148
serialize = True ,
149
+ unique = False ,
150
+ ** field_arguments
140
151
)
141
- field ._unique = False
142
152
field .name = old_field .name
143
- field .db_constraint = False
144
153
else :
145
154
transform_field (field )
146
155
fields [field .name ] = field
You can’t perform that action at this time.
0 commit comments