Using MySQL, I am trying to have a table with a composite key of multiple fields.
The issue is that some of the fields are large (255 - 1024 length), if I try to run the migration, I will get:
django.db.utils.OperationalError: (1071, 'Specified key was too long; max key length is 767 bytes')
Instead of increasing the DB's key length (or changing some other DB / table settings), I found out that I can just limit the value of the field used as a key in the migration file so that it remains within the max key length, like this:
ALTER TABLE <table> ADD UNIQUE KEY `<table>_composite_key` (`col1`, `col2`(75), `col3`, `col4`, `col5`(150));
However, this is an issue if I were to change the db engine, as that syntax might not be compatible with other.
So I'm wondering is there a way to impose limit for each field in unique_together?
Thanks in advance!