On Dec 6, 2005, at 2:01 PM, tonemcd wrote:
It seems though that Django uses ints for primary keys quite
extensively, and I guess that will cause some problems with (say)
creating new entries using the admin system.
Does anyone have any pointers/hints/howtos etc on how to do this
with a
minimum of hassle?
Although Django uses integer primary keys by default, you can use any
row as the primary key as long as you're explicit about it::
class Story(meta.Model):
headline = meta.CharField(maxlength=100)
body = meta.TextField()
would map to the following SQL::
CREATE TABLE stories (
id serial NOT NULL PRIMARY KEY,
headline varchar(100) NOT NULL,
body text NOT NULL
)
(see the automatically added primary key), but if you do this::
class Story(meta.Model):
headline = meta.CharField(maxlength=100, primary_key=True)
body = meta.TextField()
you'll get::
CREATE TABLE stories (
headline varchar(100) NOT NULL PRIMARY KEY,
body text NOT NULL
)
Clear?
Also, if you're working on an existing schema, be sure to the legacy
database documentation: http://www.djangoproject.com/documentation/
legacy_databases/
Jacob