How to change the behaviour of django_spanner application on entire django project? As I am using 2 databases inside my django application

Viewed 91

My Django application has 2 databases (spanner and AWS RDS). I am trying to integrate spanner DB with existing RDS (following the Django spanner document mentioned at the link below). It says we should include the django_spanner application inside the INSTALLED_APPS list. I have multiple applications inside my Django project but I want to use spanner only for one app. After following the steps that are mentioned in the below document, it says The django_spanner application changes the default behavior of Django's AutoField so that it generates random values (instead of automatically incrementing sequentially). This seems to be done to avoid a common anti-pattern in Cloud Spanner usage. I don't want this to happen for other tables where auto-generated id keys are getting randomly generated after including django_spanner, because the other tables will still be in AWS RDS(where we need automatically increasing ids). Can anyone please suggest any solution?

https://cloud.google.com/blog/topics/developers-practitioners/introducing-django-cloud-spanner-database

1 Answers

The django_spanner application changes the default behavior of Django's AutoField so that it generates random (instead of automatically incrementing sequential) values. In addition to AutoField it also changes the behaviour of Small/BigAutoField. This is done to avoid creation of hot spots in Cloud Spanner.

So the workaround here could be to implement your own AutoField in case of AWS RDS only and to design schema with Cloud Spanner I would suggest you to go through this document.

Related