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