some value for primary key

19 views
Skip to first unread message

Soumen Khatua

unread,
Jan 21, 2020, 1:33:20 PM1/21/20
to django...@googlegroups.com
Hi Folks,

I want to start my primary key from saome random number like: 7777(onwards)
but not from 1. How I can do that in django?

Thank you in advance

Regards,
Soumen

Suraj Thapa FC

unread,
Jan 21, 2020, 9:51:35 PM1/21/20
to django...@googlegroups.com
Just right a simple python function.... With random number generation... And call it where you want to use it

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPUw6Wbrnst2pAkdCZp%2B2jd4etsYGE_o%2BBO%2BAc85TPeyG92a3A%40mail.gmail.com.

Mike Dewhirst

unread,
Jan 21, 2020, 9:58:11 PM1/21/20
to django users
On 22/01/2020 5:32 am, Soumen Khatua wrote:
> Hi Folks,
>
> I want to start my primary key from saome random number like:
> 7777(onwards)
> but not from 1.

I wonder why?

> How I can do that in django?

If I really had to do that I would adjust the relevant sequence manually
via PGAdmin.

Otherwise, I would have to invent a single use method which only
operates if the id is 1 on creation of a model instance. That method
would have to generate the random number and execute raw SQL to update
the sequence and then update the id to match.

Another way might be to continuously create and delete records until the
id was the same as your random number.

Good luck

Mike

>
> Thank you in advance
>
> Regards,
> Soumen
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> <https://groups.google.com/d/msgid/django-users/CAPUw6Wbrnst2pAkdCZp%2B2jd4etsYGE_o%2BBO%2BAc85TPeyG92a3A%40mail.gmail.com?utm_medium=email&utm_source=footer>.

maninder singh Kumar

unread,
Jan 22, 2020, 2:50:45 AM1/22/20
to django...@googlegroups.com
you could do that in the database with a mysql statement.


ALTER TABLE tbl AUTO_INCREMENT = 7777; 
               
 


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPUw6Wbrnst2pAkdCZp%2B2jd4etsYGE_o%2BBO%2BAc85TPeyG92a3A%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages