How to disable automatic id creation in Django?

I want to disable automatic id creation in Django models. Can this be done? How?

+5
source share
1 answer

As mentioned in the answer, you need to declare a primary key in a non-automatic field. For instance:

from django.db import models class Person(models.Model): username = CharField(primary_key=True, max_length=100) first_name = CharField(null=True, blank=True, max_length=100) 

Note that setting the field to primary_key=True automatically makes it unique, not null. Good luck

+2
source

Source: https://habr.com/ru/post/1233925/


All Articles