I Wanna Resist Id In Serial Number
I wanna resist id in serial number like 1,2,3・・・.I wrote codes to resist User data like, from django.db import models import uuid # Create your models here. def get_next():
Solution 1:
UUID is not a number but you can generate a new UUID simple
import uuid
from django.db import models
# Create your models here.defget_next():
return uuid.uuid4()
classUsers(models.Model):
id = models.UUIDField(primary_key=True, default=get_next, editable=False)
sex = models.CharField(max_length=100, null=True, default=None)
age = models.CharField(max_length=100, null=True, default=None)
By default Django will store Integer Primary keys. In order to do that you need to remove some of your code.
from django.db import models
class Users(models.Model):
sex = models.CharField(max_length=100, null=True, default=None)
age = models.CharField(max_length=100, null=True, default=None)
Pending on you database backend it will be sequential.
Solution 2:
You don't need uuid for this since its only an integer! ...otherwise replace your id field with this
id = models.UUIDField(primary_key=True, default=get_next, editable=False, autoincrement)
Then do
>>>python manage.py makemigrations>>>python manage.py migrate
Post a Comment for "I Wanna Resist Id In Serial Number"