#19030: primary key in model is not primary key in database
-------------------------------------+-------------------------------------
Reporter: ccruickshank | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.3
(models, ORM) | Resolution:
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by ccruickshank):
I am using pgAdminIII to review the db tables
I created some tables in django and then wanted to simply edit them by
hand to generate some initial data
pg_admin complained and said that no editing was possible as there was no
primary key for the table
If I do not specify a primary key and instead leave it to django then it
creates an id field that is a primary key in the database
an example of such a table
{{{
class CompanyUrl(models.Model):
company = models.CharField(max_length=50)
urllink = models.CharField(max_length=200)
def __unicode__(self):
return self.company
}}}
this results in the following in pgAdminIII being displayed in the sqlpane
{{{
CREATE TABLE news_companyurl
(
id serial NOT NULL,
company character varying(50) NOT NULL,
urllink character varying(200) NOT NULL,
CONSTRAINT news_companyurl_pkey PRIMARY KEY (id )
)
WITH (
OIDS=FALSE
);
ALTER TABLE news_companyurl
OWNER TO postgres;
}}}
As you can see there is a "PRIMARY KEY" defined
The reason for using to use my own Primary Key is I want to joins tables
together based on patent numbers (these are a combination of chars and
numbers eg US7895641B1). I have used this approach succesfully in an
earlier application using a different programming language and database.
The information in the setings file is
{{{
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add
'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'osa_direct', # Or path to database file if
using sqlite3.
'USER': 'postgres', # Not used with sqlite3.
'PASSWORD': 'cintelliq', # Not used with sqlite3.
'HOST': '', # Set to empty string for
localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for
default. Not used with sqlite3.
}
}
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/19030#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.