Redshift Migrations Issues

Hello,

I new to Django and am stumped on how to add postgresql and redshift to my project.

One of my app in my project has multiple models for postgresql and now I’m trying to add a model that has an existing table in redshift, with a database router to route my migrations. However, when I try and migrate the model for redshift I get the below error.

“multiple default values specified for column ‘id’ of table ‘django_migrations’”.

This is a little confusing as I don’t have django_migrations or django_content_type tables created in redshift yet.

I then manually created django_migrations and django_conent_type and reran my migration for redshift.

“python manage.py migrate --database=redshift”

and get the following error…

“multiple default values specified for column ‘id’ of table ‘django_content_type’”.

I’m not sure where to go from here. I was thinking about trying --fake or --fake-initial for redshift migration, but don’t want to mess up anything relating to my postgres database.

My connection to redshift is good as I’m able to query the table in django shell. I was thinking it could be my router and add it below.

If anyone has any guidance or has worked through something like this before I would greatly appreciate your feedback. Thanks!

==========================
router.py

class DbRouter:

def db_for_read(self, model, **hints):
    if model._meta.app_label == 'my_site':
        if model._meta.model_name == 'GlblDrugEvents':
            return 'redshift'
        else:
            return 'default'
    return None

def db_for_write(self, model, **hints):
    if model._meta.app_label == 'my_site':
        if model._meta.model_name == 'GlblDrugEvents':
            return 'redshift'
        else:
            return 'default'
    return None

def allow_relation(self, obj1, obj2, **hints):
    if obj1._meta.app_label == 'my_site' or obj2.app_label == 'my_site':
        return True
    return None
    
def allow_migrate(self, db, app_label, model_name=None, **hints):
    if app_label == 'my_site':
        if model_name == 'GlblDrugEvents':
            return db == 'redshift'
        else:
            return db == 'default'
    return None

I assume you are using the django-redshift-backend package and running into this exact issue.

That’s a bug that will need to be fixed on the django-redshift-backend side of things.

@charettes Thanks for the quick reply. I am using django-redshift-backend. I suppose that is the issue then. Do you know of another backends for redshift out there or have you used anything else that works?

I’m not really familiar with the landscape of tools to interface with Redshift unfortunately.

The signature of the error your reported made me search multiple default values specified for column ‘id’ of table ‘django_migrations in all issues tracker associated with Pypi packages returned for django redshift.