Take a look at how syncdb names constraints:
backend.quote_name('%s_referencing_%s_%s' % (r_col, table, col))
In some circumstances, syncdb generates the same constraint name (for foreign keys= for different tables. Now, using both table names in the name can lead to too long names, so this isn't a solution. I propose to use a hash of both table names + the two attribute names. A quick, easy and dirty version is:
backend.quote_name('%s_referencing_%s_%x' % (r_col, col, hash((r_table, table))))
Here's an example.
class Man(models.Model):
father = ForeignKey(Man, null=True)
class Woman(models.Model):
father = ForeignKey(Man, null=True)
These will (currently) both create the constraint 'father_referencing_man_id' (resulting in incomprehensible error message in case of mysql)