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?
Asked
Active
Viewed 165 times
1 Answers
0
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

kmmbvnr
- 5,863
- 4
- 35
- 44
-
I haven't head of virtual fields before. Could you give an example of how you would use this to get a model to reference another model that have composite primary keys? – Kasper Skjeggestad Feb 26 '21 at 07:07