#343 closed defect (fixed)
One-to-one relations - different primary_key
| Reported by: | Bless | Owned by: | Adrian Holovaty |
|---|---|---|---|
| Component: | Metasystem | Version: | dev |
| Severity: | normal | Keywords: | One-to-one |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
When is used a different primary_key (no integer) in One-to-one relations, id is always a integer
class Nic(meta.Model):
fields = (
meta.CharField('name', maxlength=4),
)
class Network(meta.Model):
fields = (
meta.OneToOneField(nics.Nic),
meta.CharField('name', maxlength=3, choices=NETWORK_TYPES, unique=True),
)
BEGIN;
CREATE TABLE nics_nics (
id integer NOT NULL PRIMARY KEY,
name varchar(4) NOT NULL
);
CREATE TABLE nics_networks (
id integer NOT NULL PRIMARY KEY REFERENCES nics_nics (id),
name varchar(3) NOT NULL UNIQUE
);
COMMIT;
id integer NOT NULL PRIMARY KEY REFERENCES nics_nics (id), -> OK
class Nic(meta.Model):
fields = (
meta.CharField('name', maxlength=4, primary_key=True),
)
class Network(meta.Model):
fields = (
meta.OneToOneField(nics.Nic),
meta.CharField('name', maxlength=3, choices=NETWORK_TYPES, unique=True),
)
BEGIN;
CREATE TABLE nics_nics (
name varchar(4) NOT NULL PRIMARY KEY
);
CREATE TABLE nics_networks (
id integer NOT NULL PRIMARY KEY REFERENCES nics_nics (name),
name varchar(3) NOT NULL UNIQUE
);
COMMIT;
id integer NOT NULL PRIMARY KEY REFERENCES nics_nics (name), -> Bug
It should be varchar in this case.
Change History (5)
comment:1 by , 20 years ago
| Component: | Core framework → Metasystem |
|---|
comment:2 by , 19 years ago
| Severity: | major → normal |
|---|---|
| Version: | 1.0 → SVN |
comment:4 by , 19 years ago
Note:
See TracTickets
for help on using tickets.
The problem here is that
OneToOneFieldinherits fromIntegerField. Fixing it will require changing that, and the question is whether to inherit directly fromFieldas foreign keys do, or to inherit fromForeignKeyField(since that's what it ends up being in the DB).