jazzband / django-redshift-backend

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

sqlmigrate for drop table cause exception #8

Closed shimizukawa closed 2 years ago

shimizukawa commented 8 years ago

versions:

command

python manage.py sqlmigrate some_app 0011

migration: 0011_auto_20160915_1639.py

# -*- coding: utf-8 -*-
# Generated by Django 1.9.9 on 2016-09-15 16:39
from __future__ import unicode_literals

from django.db import migrations

class Migration(migrations.Migration):

    dependencies = [
        ('some_app', '0010_auto_20160531_1751'),
    ]

    operations = [
        migrations.RemoveField(
            model_name='term',
            name='format',
        ),
        migrations.DeleteModel(
            name='Term',
        ),
    ]

traceback

Traceback (most recent call last):
  File "apps/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "~/.venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "~/.venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "~/.venv/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "~/.venv/lib/python2.7/site-packages/django/core/management/commands/sqlmigrate.py", line 31, in execute
    return super(Command, self).execute(*args, **options)
  File "~/.venv/lib/python2.7/site-packages/raven/contrib/django/management/__init__.py", line 41, in new_execute
    return original_func(self, *args, **kwargs)
  File "~/.venv/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "~/.venv/lib/python2.7/site-packages/django/core/management/commands/sqlmigrate.py", line 57, in handle
    sql_statements = executor.collect_sql(plan)
  File "~/.venv/lib/python2.7/site-packages/django/db/migrations/executor.py", line 177, in collect_sql
    state = migration.apply(state, schema_editor, collect_sql=True)
  File "~/.venv/lib/python2.7/site-packages/django/db/migrations/migration.py", line 123, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "~/.venv/lib/python2.7/site-packages/django/db/migrations/operations/fields.py", line 121, in database_forwards
    schema_editor.remove_field(from_model, from_model._meta.get_field(self.name))
  File "~/.venv/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 430, in remove_field
    fk_names = self._constraint_names(model, [field.column], foreign_key=True)
  File "~/.venv/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 911, in _constraint_names
    constraints = self.connection.introspection.get_constraints(cursor, model._meta.db_table)
  File "~/.venv/lib/python2.7/site-packages/django/db/backends/postgresql/introspection.py", line 189, in get_constraints
    """, ["public", table_name])
  File "~/.venv/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "~/.venv/lib/python2.7/site-packages/raven/contrib/django/client.py", line 112, in execute
    return real_execute(self, sql, params)
  File "~/.venv/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "~/.venv/lib/python2.7/site-packages/django/db/utils.py", line 95, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "~/.venv/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: must be superuser to examine "max_index_keys"
CONTEXT:  SQL function "_pg_keypositions" statement 1
shimizukawa commented 2 years ago

Now it works. This problem was caused by the fact that get_constraints method not working with Redshift. But it is now fixed in #90.

(.venv) @shimizukawa ➜ /workspaces/django-redshift-backend/examples/proj1 (feature/dj40 ✗) $ python manage.py sqlmigrate testapp 0002
--
-- Remove field parent from testchildmodel
--
ALTER TABLE "testapp_testchildmodel" DROP CONSTRAINT "testapp_testchildmod_parent_id_c460c524_fk_testapp_t";
ALTER TABLE "testapp_testchildmodel" DROP COLUMN "parent_id" CASCADE;
--
-- Remove field fk from testmodelwithmetakeys
--
ALTER TABLE "testapp_testmodelwithmetakeys" DROP CONSTRAINT "testapp_testmodelwit_fk_id_6f46321c_fk_testapp_t";
ALTER TABLE "testapp_testmodelwithmetakeys" DROP COLUMN "fk_id" CASCADE;