Repository: SmileyChris/django-countries

Issue:
Applying migrations with CountryField fails with Django 3.2
I've created a simple model with a `CountryField`.  Creating a migration for this model works fine (at least when using the latest version from Git).  However, applying the migration fails (traceback included below).

**Environment:**
- Django 3.2b1 (from PyPI)
- django-countries 7.1.dev0 (latest version from Git)

**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 "venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "venv/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "venv/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "venv/lib/python3.8/site-packages/django/core/management/base.py", line 89, in wrapped
    res = handle_func(*args, **kwargs)
  File "venv/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 75, in handle
    self.check(databases=[database])
  File "venv/lib/python3.8/site-packages/django/core/management/base.py", line 419, in check
    all_issues = checks.run_checks(
  File "venv/lib/python3.8/site-packages/django/core/checks/registry.py", line 76, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
  File "venv/lib/python3.8/site-packages/django/core/checks/model_checks.py", line 34, in check_all_models
    errors.extend(model.check(**kwargs))
  File "venv/lib/python3.8/site-packages/django/db/models/base.py", line 1271, in check
    *cls._check_fields(**kwargs),
  File "venv/lib/python3.8/site-packages/django/db/models/base.py", line 1380, in _check_fields
    errors.extend(field.check(**kwargs))
  File "venv/lib/python3.8/site-packages/django_countries/fields.py", line 285, in check
    errors = super().check(**kwargs)
  File "venv/lib/python3.8/site-packages/django/db/models/fields/__init__.py", line 1013, in check
    *self._check_db_collation(databases),
  File "venv/lib/python3.8/site-packages/django/db/models/fields/__init__.py", line 1045, in _check_db_collation
    self.db_collation is None or
AttributeError: 'CountryField' object has no attribute 'db_collation'
```

Comments:

Patch:
diff --git a/django_countries/fields.py b/django_countries/fields.py
index 3b3db00..ee211f1 100644
--- a/django_countries/fields.py
+++ b/django_countries/fields.py
@@ -279,7 +279,7 @@ class CountryField(CharField):
                 kwargs["max_length"] = len(self.countries) * 3 - 1
             else:
                 kwargs["max_length"] = 2
-        super(CharField, self).__init__(*args, **kwargs)
+        super().__init__(*args, **kwargs)
 
     def check(self, **kwargs):
         errors = super().check(**kwargs)


Test patch:
diff --git a/django_countries/tests/test_fields.py b/django_countries/tests/test_fields.py
index 43316ca..983dc1b 100644
--- a/django_countries/tests/test_fields.py
+++ b/django_countries/tests/test_fields.py
@@ -1,7 +1,9 @@
 import pickle
 import tempfile
 from unittest import mock
+from unittest.case import skipUnless
 
+import django
 from django.db import models
 from django.core import validators, checks
 from django.core.management import call_command
@@ -17,7 +19,20 @@ from django_countries.tests import forms, custom_countries
 from django_countries.tests.models import Person, AllowNull, MultiCountry, WithProp
 
 
+# Django 3.2 introduced a db_collation attr on fields.
+def has_db_collation():
+    major, minor = django.VERSION[0:2]
+    return (major > 3) or (major==3 and minor >=2)
+
+
 class TestCountryField(TestCase):
+
+    @skipUnless(has_db_collation(), "Django version < 3.2")
+    def test_db_collation(self):
+        # test fix for issue 338
+        country = fields.CountryField()
+        self.assertTrue(hasattr(country, "db_collation"))
+
     def test_logic(self):
         person = Person(name="Chris Beaven", country="NZ")