Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#14353 closed (worksforme)

unique_together new style is not working properly

Reported by: draxus Owned by: nobody
Component: Uncategorized Version: 1.2
Severity: Keywords: unique, restriction
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

As you say in django docs: http://docs.djangoproject.com/en/dev/ref/models/options/#unique-together

unique_together = ("driver", "restaurant") <- this way doesn't create the unique restrictions in the DB

unique_together = (("driver", "restaurant"),) <- this way works great

Change History (2)

comment:1 Changed 4 years ago by ramiro

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to worksforme
  • Status changed from new to closed

Tested this with Django 1.1, 1.2.X and trunk plus sqlite3 with the following model:

from django.db import models

class Foo(models.Model):
    driver = models.CharField(max_length=20)
    restaurant = models.CharField(max_length=30)
    age = models.PositiveIntegerField()

    class Meta:
        unique_together = (('driver', 'restaurant'),)
        #unique_together = ('driver', 'restaurant')

using both forms of unique_together. In all cases the SQL generated (manage.py sqlall <app name>) is:

BEGIN;CREATE TABLE "t14353_foo" (
    "id" integer NOT NULL PRIMARY KEY,
    "driver" varchar(20) NOT NULL,
    "restaurant" varchar(30) NOT NULL,
    "age" integer unsigned NOT NULL,
    UNIQUE ("driver", "restaurant")
)
;COMMIT;

We'd need more details about you setup (exact Django version, revision and DB backend you are using) and a minimal example like the one above demonstrating the issue.

comment:2 Changed 4 years ago by draxus

Today is working in both ways. What a mistery...

I will reopen this ticket if it happens again. Thank you very much for your answer.

Note: See TracTickets for help on using tickets.
Back to Top