jazzband / django-redshift-backend

Redshift database backend for Django
Apache License 2.0
83 stars 47 forks source link

Key Error in _alter_column_type_sql #130

Closed kylie-sre closed 4 months ago

kylie-sre commented 5 months ago

Subject: There is a KeyError occurring in _alter_column_type_sql

Problem

Procedure to reproduce the problem

$ ~/.venvs/events/bin/python manage.py migrate schemas --database redshift
Operations to perform:
  Apply all migrations: schemas
Running migrations:
  Applying schemas.0006_alter_loginevent_username...Traceback (most recent call last):
  File "/Users/kylie/apps/event-pipeline/events/manage.py", line 22, in <module>
    main()
  File "/Users/kylie/apps/event-pipeline/events/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/Users/kylie/.venvs/events/lib/python3.9/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/Users/kylie/.venvs/events/lib/python3.9/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/kylie/.venvs/events/lib/python3.9/site-packages/django/core/management/base.py", line 412, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/kylie/.venvs/events/lib/python3.9/site-packages/django/core/management/base.py", line 458, in execute
    output = self.handle(*args, **options)
  File "/Users/kylie/.venvs/events/lib/python3.9/site-packages/django/core/management/base.py", line 106, in wrapper
    res = handle_func(*args, **kwargs)
  File "/Users/kylie/.venvs/events/lib/python3.9/site-packages/django/core/management/commands/migrate.py", line 356, in handle
    post_migrate_state = executor.migrate(
  File "/Users/kylie/.venvs/events/lib/python3.9/site-packages/django/db/migrations/executor.py", line 135, in migrate
    state = self._migrate_all_forwards(
  File "/Users/kylie/.venvs/events/lib/python3.9/site-packages/django/db/migrations/executor.py", line 167, in _migrate_all_forwards
    state = self.apply_migration(
  File "/Users/kylie/.venvs/events/lib/python3.9/site-packages/django/db/migrations/executor.py", line 252, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/Users/kylie/.venvs/events/lib/python3.9/site-packages/django/db/migrations/migration.py", line 132, in apply
    operation.database_forwards(
  File "/Users/kylie/.venvs/events/lib/python3.9/site-packages/django/db/migrations/operations/fields.py", line 235, in database_forwards
    schema_editor.alter_field(from_model, from_field, to_field)
  File "/Users/kylie/.venvs/events/lib/python3.9/site-packages/django/db/backends/base/schema.py", line 831, in alter_field
    self._alter_field(
  File "/Users/kylie/.venvs/events/lib/python3.9/site-packages/django_redshift_backend/base.py", line 426, in _alter_field
    fragment, other_actions = self._alter_column_type_sql(model, old_field, new_field, new_type)
  File "/Users/kylie/.venvs/events/lib/python3.9/site-packages/django_redshift_backend/base.py", line 763, in _alter_column_type_sql
    "changes": self.sql_alter_column_type % {
KeyError: 'collation'

Error logs / results

n/a

Expected results

The migration should complete successfully

Environment info

shimizukawa commented 4 months ago

Thank you for your report. However, django-redshift-backend is not compatible with Django 4.1 or later. I'm currently working on making Django 4.2 compatible at https://github.com/jazzband/django-redshift-backend/pull/129. If you like, please check whether the problem you reported has been fixed using the code in PR #129.

shimizukawa commented 4 months ago

In my opinion, this problem occurs when using django-redshift-backend with Django 4.1 or later. I plan to release django-redshift-backend version 4.0.0, which is compatible with Django-4.2, soon.

shimizukawa commented 4 months ago

Now django-redshift-backend 4.0.0 has been released.