Closed karthikr87 closed 2 years ago
I came across the same issue. Please let me know in case of any solution available. It Will be a great help, thanks.
I also facing the same issue.
I also faced the same problem trying to run migrate on a brand new Django project, on the admin models.
What happens is that redshift-backend tries to add a SORTKEY parameter to the CREATE TABLE statement, and for that it uses the model._meta.ordering
list. The problem is that, in Django, you can specify columns from other models in ordering
. For this columns, the list will show an entry in the format "model__column", which is invalid for Redshift, since it's not a valid column for that model. This is specially true for Django content_types.
I also noticed that, even if you fix this issue to only add columns from the same model on the SORTKEY, it will throw another exception when some migration tries to delete a column that is part of the SORTKEY (which, also, the default migrations for Django Admin do).
The only way I found to work around this issue was to remove the SORTKEY parameter from the CREATE TABLE statements created by this component. I did this by commenting lines 533:539 in base.py on the django_redshift_backend package.
I this this is also related to issue #37 .
EDIT: Just as a follow up, even after fixing all the problems above (and others that came up after) I found that Django 3.2 will, probably, be incompatible with Redshift. It generates SQL statements with functions not supported by Redshift (such as unnest()). So I'm giving up using Redshift with Django, at least for my current project. This is not related with django-redshift-backend, but with Django ORM itself.
@sebastiaopf Thank you for the detailed report!
I think it is because of the idea of using Model.Meta.ordering
for SORTKEY (https://github.com/jazzband/django-redshift-backend/pull/20).
It seems to me that having a separate setting value, for example sortkey
, would solve this problem.
The other problem you mentioned, the use of functions not supported by Redshift such as unnest()
, can be addressed if we know what kind of SQL is being generated by what kind of ORM queries.
Since this backend is based on the postgres backend, it is affected by the addition of features to the base. Each time this happens, we need to adjust the SQL syntax and functions that are not available in Redshift. However, since these backend developers can't keep track of everything by themselves, it would be great if you could let us know when you find something.
It has been released https://pypi.org/project/django-redshift-backend/3.0.0/
Subject: Migrate classic redshift DB to django model
Problem
'python manage.py makemigrations' - succeeded 'python manage.py migrate - error msg: django.db.utils.NotSupportedError: column "content_type__app_label" specified as distkey/sortkey is not in the table "auth_permission"
Procedure to reproduce the problem
Error logs / results
Expected results
results in success. Create tables for admin user. Create model file from existing db using inspectdb
Environment info