Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Renaming default id column in Django models

I have an existing application written in Django and I am taking advantage of the models, migrations orm etc.

Each model has a column id I was wondering if it is possible to rename this column to something else like person_id

I saw some examples creating new primary key columns but that is not what i want. I want to rename the existing id column name

like image 876
jonprasetyo Avatar asked Feb 07 '23 04:02

jonprasetyo


1 Answers

You've said its not what you want but the answer is to make your own primary key,

From the docs,

If you’d like to specify a custom primary key, just specify primary_key=True on one of your fields. If Django sees you’ve explicitly set Field.primary_key, it won’t add the automatic id column.

Since it doesn't add the automatic id column, you've effectively renamed it

like image 182
Sayse Avatar answered Feb 12 '23 15:02

Sayse