Working with composite primary key and foreign keys in django project with legacy database

179 Views Asked by At

In this question, e4c5 suggests updating tables in the legacy database with a single primary key to work with Django. However, every table referencing the updated table will be using the composite primary key as reference and will therefore not work in Django. Is there a way to either update the tables so they would use the new primary key, or a workaround for this?

1

There are 1 best solutions below

1
kmmbvnr On

I make a virtual primary key field implementation, that represents composite key as a single json value, that tricks Django, and allows to access to legacy db without table altering - https://viewflow.medium.com/the-django-compositeforeignkey-field-get-access-to-a-legacy-database-without-altering-db-tables-74abc9868026