﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
2257	[patch] syncdb should generate unique constraint names with hashes	mir@…	Malcolm Tredinnick	"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)
"	defect	closed	Core (Management commands)		normal	fixed			Unreviewed	1	0	0	0	0	0
