# Buggy code
def create_unique_slugs_for_producttypes(apps, schema_editor):
    ProductType = apps.get_model("product", "ProductType")

    product_types = (
        ProductType.objects.filter(slug__isnull=True).order_by(Lower("name")).iterator()
    )
    previous_char = ""
    slug_values = []
    for product_type in product_types:
        first_char = product_type.name[0].lower()
        if first_char != previous_char:
            previous_char = first_char
            slug_values = ProductType.objects.filter(
                slug__istartswith=first_char
            ).values_list("slug", flat=True)

        slug = generate_unique_slug(product_type, slug_values)
        product_type.slug = slug
        slug_values.append(slug)


# Traceback (AttributeError)
Operations to perform:
Apply all migrations: account, auth, checkout, contenttypes, core, discount, django_prices_openexchangerates, django_prices_vatlayer, extensions, giftcard, menu, order, page, payment, product, shipping, site, sites, warehouse, webhook, wishlist
Running migrations:
Applying product.0112_auto_20200129_0050...Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 369, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 231, in handle
post_migrate_state = executor.migrate(
File "/usr/local/lib/python3.8/site-packages/django/db/migrations/executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/usr/local/lib/python3.8/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/usr/local/lib/python3.8/site-packages/django/db/migrations/executor.py", line 245, in apply_migration
state = migration.apply(state, schema_editor)
File "/usr/local/lib/python3.8/site-packages/django/db/migrations/migration.py", line 124, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/usr/local/lib/python3.8/site-packages/django/db/migrations/operations/special.py", line 190, in database_forwards
self.code(from_state.apps, schema_editor)
File "/app/saleor/product/migrations/0112_auto_20200129_0050.py", line 28, in create_unique_slugs_for_producttypes
slug_values.append(slug)
AttributeError: 'QuerySet' object has no attribute 'append'

# Fixed code
def create_unique_slugs_for_producttypes(apps, schema_editor):
    ProductType = apps.get_model("product", "ProductType")

    product_types = (
        ProductType.objects.filter(slug__isnull=True).order_by(Lower("name")).iterator()
    )
    previous_char = ""
    slug_values = []
    for product_type in product_types:
        first_char = product_type.name[0].lower()
        if first_char != previous_char:
            previous_char = first_char
            slug_values = list(
                ProductType.objects.filter(slug__istartswith=first_char).values_list(
                    "slug", flat=True
                )
            )

        slug = generate_unique_slug(product_type, slug_values)
        product_type.slug = slug
        slug_values.append(slug)