django/django — pull request #1813 by pricco (2013-10-26 06:21:15+00:00)
Title: Fixed #19750 Postgres conflict on CREATE INDEX: "relation exists"

[#19750](https://code.djangoproject.com/ticket/19750) Improve index name on postgres in order to avoid name conflicts.

---

## Failing test

Django Version: stable/1.5.x

`pip install git+git://github.com/django/django.git@stable/1.5.x#egg=Django`

**`models.py`**

```python
from django.db import models

class OrganizationType(models.Model):
id = models.CharField(max_length=1, primary_key=True)

class Meta:
db_table = 'organization_type'

class Organization(models.Model):
type = models.ForeignKey(OrganizationType)
class Meta:
db_table = 'organization'
```

**`./manage.py sqlall`**
```sql
BEGIN;
CREATE TABLE "organization_type" (
"id" varchar(1) NOT NULL PRIMARY KEY,
"name" varchar(10) NOT NULL
)
;
CREATE TABLE "organization" (
"id" serial NOT NULL PRIMARY KEY,
"type_id" varchar(1) NOT NULL REFERENCES "organization_type" ("id") DEFERRABLE INITIALLY DEFERRED
)
;
CREATE INDEX "organization_type_id_like" ON "organization_type" ("id" varchar_pattern_ops);
CREATE INDEX "organization_type_id" ON "organization" ("type_id");
CREATE INDEX "organization_type_id_like" ON "organization" ("type_id" varchar_pattern_ops);

COMMIT;
```