CREATE TABLE foo ( id serial primary key, other_id int UNIQUE);
CREATE TABLE bar ( id serial primary key, other_id int,
constraint myconst
FOREIGN
KEY(other_id) references foo(other_id)
);
the generated model for the bar table will have the other_id be a FK to
foo and not foo(other_id).
I'm attaching a potential fix for this. Sorry I had no time for the UTs.
--
Ticket URL: <https://code.djangoproject.com/ticket/33187>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* Attachment "handle_fk_to_field.diff" added.
simple patch to handle FK to non pk field.
* status: new => closed
* resolution: => invalid
Comment:
it seems I cannot reproduce outside of my own code...
--
Ticket URL: <https://code.djangoproject.com/ticket/33187#comment:1>
* status: closed => new
* resolution: invalid =>
--
Ticket URL: <https://code.djangoproject.com/ticket/33187#comment:2>
* type: Uncategorized => Bug
* component: Uncategorized => Database layer (models, ORM)
Old description:
> if you have a DB like that
>
> CREATE TABLE foo ( id serial primary key, other_id int UNIQUE);
>
> CREATE TABLE bar ( id serial primary key, other_id int,
> constraint myconst
> FOREIGN KEY(other_id) references foo(other_id)
> );
>
> the generated model for the bar table will have the other_id be a FK to
> foo and not foo(other_id).
>
> I'm attaching a potential fix for this. Sorry I had no time for the UTs.
New description:
if you have a DB like that
{{{#!sql
CREATE TABLE foo ( id serial primary key, other_id int UNIQUE);
CREATE TABLE bar (
id serial primary key, other_id int,
constraint myconst
FOREIGN KEY(other_id) references foo(other_id)
);
}}}
the generated model for the bar table will have the other_id be a FK to
foo and not foo(other_id).
I'm attaching a potential fix for this. Sorry I had no time for the UTs.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/33187#comment:3>
* has_patch: 1 => 0
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/33187#comment:4>
* owner: nobody => Jordan Bae
* status: new => assigned
Comment:
I will check it!
--
Ticket URL: <https://code.djangoproject.com/ticket/33187#comment:5>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/15037 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/33187#comment:6>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/33187#comment:7>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/33187#comment:8>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/33187#comment:9>
* status: assigned => closed
* resolution: => fixed
Comment:
Fixed in
[https://github.com/django/django/commit/aaf9b558583d9bb75a0c9d53b135dc8c1b75b6a2
aaf9b558583d9bb75a0c9d53b135dc8c1b75b6a2].
--
Ticket URL: <https://code.djangoproject.com/ticket/33187#comment:10>