Django 3.2 AttributeError: 'TextField' object has no attribute 'db_collation'

483 views
Skip to first unread message

Asaduzzaman Sohel

unread,
Apr 7, 2021, 3:50:48 AM4/7/21
to Django users
I've an existing project on Django 3.1 and I upgraded my project to Django 3.2. I created an app called payment on my project. But When I make migrations. It trow an error 
```AttributeError: 'TextField' object has no attribute 'db_collation'```
```
from django.db import models
from django.conf import settings
from django.utils.translation import gettext_lazy as _
# Create your models here.
from simple_history.models import HistoricalRecords


class TransactionType(models.TextChoices):
    CASH_IN = 'IN', _('Cash In')
    CASH_OUT = 'OUT', _('Cash Out')


class TransactionMethod(models.TextChoices):
    STUDENT_TR = 'STT', _('Student Transaction')
    BANK_TR = 'BKT', _('Bank Transaction')
    SCHOOL_TR = 'SLT', _('School Transaction')
    Teacher_TR = 'TRT', _('Teacher Transaction')
    DONATE_TR = 'DET', _('Donate Transaction')


class Payment(models.Model):
    id = models.AutoField(primary_key=True)
    created_by = models.ForeignKey(settings.AUTH_USER_MODEL,
                                   on_delete=models.PROTECT,
                                   related_name="created_by")
    updated_by = models.ForeignKey(settings.AUTH_USER_MODEL,
                                   on_delete=models.PROTECT,
                                   related_name="updated_by")
    transaction_amount = models.FloatField("Transaction amount")
    transaction_type = models.CharField(max_length=3, choices=TransactionType.choices, default=TransactionType.CASH_IN,)
    transaction_method = models.CharField(max_length=3, choices=TransactionMethod.choices, default=TransactionMethod.STUDENT_TR,)
    transaction_note = models.CharField(null=True, blank=True, max_length=200)
    is_approved = models.BooleanField(default=False)
    is_approved_by_user = models.ForeignKey(settings.AUTH_USER_MODEL,
                                            on_delete=models.PROTECT,
                                            related_name="approved_by",
                                            null=True,
                                            blank=True)
    created_at = models.DateTimeField(auto_now=True, blank=True, null=True)
    updated_at = models.DateTimeField(auto_now_add=True, blank=True, null=True)
    history = HistoricalRecords()


```

Full error message 
```Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/home/asad/PycharmProjects/amarschool/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/home/asad/PycharmProjects/amarschool/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/asad/PycharmProjects/amarschool/venv/lib/python3.6/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/asad/PycharmProjects/amarschool/venv/lib/python3.6/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/home/asad/PycharmProjects/amarschool/venv/lib/python3.6/site-packages/django/core/management/base.py", line 89, in wrapped
    res = handle_func(*args, **kwargs)
  File "/home/asad/PycharmProjects/amarschool/venv/lib/python3.6/site-packages/django/core/management/commands/makemigrations.py", line 150, in handle
    ProjectState.from_apps(apps),
  File "/home/asad/PycharmProjects/amarschool/venv/lib/python3.6/site-packages/django/db/migrations/state.py", line 220, in from_apps
    model_state = ModelState.from_model(model)
  File "/home/asad/PycharmProjects/amarschool/venv/lib/python3.6/site-packages/django/db/migrations/state.py", line 407, in from_model
    fields.append((name, field.clone()))
  File "/home/asad/PycharmProjects/amarschool/venv/lib/python3.6/site-packages/django/db/models/fields/__init__.py", line 512, in clone
    name, path, args, kwargs = self.deconstruct()
  File "/home/asad/PycharmProjects/amarschool/venv/lib/python3.6/site-packages/django/db/models/fields/__init__.py", line 2173, in deconstruct
    if self.db_collation:
AttributeError: 'TextField' object has no attribute 'db_collation'
```
Reply all
Reply to author
Forward
0 new messages