开发者

How to mention other field as Foreign Key in Django Model

开发者 https://www.devze.com 2023-03-15 20:14 出处:网络
In my model i have book_id PK boo开发者_运维技巧k_number as unique field Now in my Author model i want to set up

In my model i have

book_id PK
boo开发者_运维技巧k_number as unique field

Now in my Author model i want to set up

book_number as Foreign key not book_id

Is this possible


to_field.


ForeignKey refers to an entity by it's primary key, by database design. You should probably not do it although, you might be able to fake it within django by lieing within Model.Meta what the primary key is.

The right approach seems to me, is to make the book_number, the PK, if you are confident there aren't any repeats, and may be still retain the serial type for book_id.

0

精彩评论

暂无评论...
验证码 换一张
取 消