Skip to content

Commit 6241395

Browse files
committed
Added support for django-nonrel string AutoField primary key.
1 parent 0001c47 commit 6241395

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

simple_history/models.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,11 @@ def get_field(self, other, cls):
265265
if isinstance(to_field, models.OneToOneField):
266266
field = self.get_one_to_one_field(to_field, other)
267267
elif isinstance(to_field, models.AutoField):
268-
field.__class__ = models.IntegerField
268+
# Check if AutoField is string for django-non-rel support
269+
if isinstance(field, models.TextField):
270+
field.__class__ = models.TextField
271+
else:
272+
field.__class__ = models.IntegerField
269273
else:
270274
field.__class__ = to_field.__class__
271275
excluded_prefixes = ("_", "__")
@@ -319,7 +323,12 @@ def transform_field(field):
319323
if isinstance(field, models.AutoField):
320324
# The historical model gets its own AutoField, so any
321325
# existing one must be replaced with an IntegerField.
322-
field.__class__ = models.IntegerField
326+
if isinstance(field, models.TextField):
327+
# Check if AutoField is string for django-non-rel support
328+
field.__class__ = models.TextField
329+
else:
330+
field.__class__ = models.IntegerField
331+
323332
elif isinstance(field, models.FileField):
324333
# Don't copy file, just path.
325334
field.__class__ = models.TextField

0 commit comments

Comments
 (0)