﻿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
19030	primary key in model is not primary key in database	ccruickshank	nobody	"I've recently started using Django for a smallish project. 
At the moment I'm developing models but have noticed a possible bug

A ""primary key"" created in the model is not a ""primary key"" in the Postgres db but ""unique"" is this a bug?

The sqlall code suggest that it is attempting to create a tabel with the right structure, but the database shows the field to be ""unique"" and not ""primary key""


== Model info ==

{{{
from django.db import models

# Create your models here.

class ModelTest(models.Model):
    pkey=models.CharField(max_length=20, primary_key=True)
    ukey=models.CharField(max_length=20,unique=True)
}}}
    
== sqlall info ==
{{{
C:\dev\patinbox>python manage.py sqlall micropat_db
BEGIN;
CREATE TABLE ""micropat_db_modeltest"" (
    ""pkey"" varchar(20) NOT NULL PRIMARY KEY,
    ""ukey"" varchar(20) NOT NULL UNIQUE
)
;
}}}    
    
    
== extract from postgres database (version 9.1)==

{{{    
-- Table: micropat_db_modeltest

-- DROP TABLE micropat_db_modeltest;

CREATE TABLE micropat_db_modeltest
(
  pkey character varying(20) NOT NULL,
  ukey character varying(20) NOT NULL,
  CONSTRAINT micropat_db_modeltest_pkey_uniq UNIQUE (pkey ),
  CONSTRAINT micropat_db_modeltest_ukey_key UNIQUE (ukey )
)
WITH (
  OIDS=FALSE
);
ALTER TABLE micropat_db_modeltest
  OWNER TO postgres;
}}}"	Bug	closed	Database layer (models, ORM)	1.3	Normal	fixed			Unreviewed	0	0	0	0	0	0
