Yes, first you generate your custom key, second you specify it as the id of
an object.
id = 'A1B2C3D4E5'
foo = Foo(id=id)
foo.save()
This code would create a record in the database. I also have to note that
if you read this record to an object, changed it and saved it, the record
wouldn't change
On 24 Jun 2020, at 06:24, Soumen Khatua wrote:
Yes, at the time of add a new record in model, automatically I want
to create a custom ID and insert it into model
There is a post about this at Stack Overflow:
https://stackoverflow.com/questions/52070462/django-generate-custom-id
-- Clive
Yes, at the time of add a new record in model, automatically I want to
create a custom ID and insert it into model
On Wed 24 Jun, 2020, 7:18 AM Clive Bruton, wrote:
>
> On 23 Jun 2020, at 23:32, Oleg Kishenkov wrote:
>
> > Hello Soumen, you should use a CharField with the primary_key=True
> > at
On 23 Jun 2020, at 23:32, Oleg Kishenkov wrote:
Hello Soumen, you should use a CharField with the primary_key=True
attribute for your model. This way no no automatic primary key
field is generated, your field will be implicitly unique and non-
null though. Only one primary key is allowed i
Hello Soumen, you should use a CharField with the primary_key=True
attribute for your model. This way no no automatic primary key field is
generated, your field will be implicitly unique and non-null though. Only
one primary key is allowed in a model.
class Foo(models.Model)
id = models.Cha
In the documentation they are specified, How to set Primary Key in Django
model but In my case, I want to generate custom Primary Key?!
On Wed, Jun 24, 2020 at 1:36 AM David Chorpash
wrote:
> Hi Soumen,
>
> Are you looking for this?
> https://docs.djangoproject.com/en/3.0/ref/models/fields/#prim
Hi Soumen,
Are you looking for this?
https://docs.djangoproject.com/en/3.0/ref/models/fields/#primary-key
You should be able to create a field in your model and set the primary_key
to True
On Tue, Jun 23, 2020 at 1:18 PM Soumen Khatua
wrote:
> Hi Folks,
>
> In Django is there any way to creat
Thank you for your time and response Malcom, I appreciate it very
much.
On Apr 29, 3:42 pm, Malcolm Tredinnick
wrote:
> On Wed, 2009-04-29 at 15:37 -0700, Timboy wrote:
> > I am trying to make a pk for an object that starts with the year
> > followed by seven additional digits. YYXXX I want
On Wed, 2009-04-29 at 15:37 -0700, Timboy wrote:
> I am trying to make a pk for an object that starts with the year
> followed by seven additional digits. YYXXX I want the digits to
> automatically increase like normal.
>
> I'm guessing I need to pass force_insert=True to my save if not
> sel
Hi Ian
Sorry for taking a while to get back to you but I've been away.
Thanks for your advice. I will log a bug.
I have also found a couple of other issues and will report those as
well.
Regards
Catriona
On Aug 16, 3:44 pm, Ian <[EMAIL PROTECTED]> wrote:
> On Aug 15, 9:43 pm, Catriona <[EMAI
On Aug 15, 9:43 pm, Catriona <[EMAIL PROTECTED]> wrote:
> Hi Ian
>
> Sorry I wasn't really clear in what I want to achieve. I really just
> want to call my primary key, in this case, employee_id and have it
> incremented automatically.
Sorry I misunderstood you. The code you tried appears to be
Hi Ian
Sorry I wasn't really clear in what I want to achieve. I really just
want to call my primary key, in this case, employee_id and have it
incremented automatically.
I tried the following:
from django.db import models
class Employee(models.Model):
employee_id = models.AutoField(max_len
Catriona,
Only AutoFields are auto-incrementing in Django. If you want to use a
custom primary key that isn't an AutoField, you will need to populate
the primary key yourself (or else create a custom trigger for it),
just as you would for any other column that is both NOT NULL and
UNIQUE. This
Hi Jon
Thanks for your reply. I read the article but with Oracle, a sequence
and trigger needs to be created for autogenerated primary keys. If I
try the code that you gave me, neither the sequence nor trigger are
created - ie
C:\DjangoTraining\PK>python manage.py sql test
CREATE TABLE "TEST_EMP
Catriona,
I have very little Oracle experience, but also no reason to think that
setting a custom primary key would be different from any other
database backend.
The documentation is here:
http://www.djangoproject.com/documentation/models/custom_pk/
The primary key is set by using 'primary_key=
15 matches
Mail list logo