Re: Custom Primary Key

2020-06-24 Thread Oleg Kishenkov
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

Re: Custom Primary Key

2020-06-24 Thread Clive Bruton
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

Re: Custom Primary Key

2020-06-23 Thread Soumen Khatua
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

Re: Custom Primary Key

2020-06-23 Thread Clive Bruton
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

Re: Custom Primary Key

2020-06-23 Thread Oleg Kishenkov
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

Re: Custom Primary Key

2020-06-23 Thread Soumen Khatua
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

Re: Custom Primary Key

2020-06-23 Thread David Chorpash
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

Re: Custom primary key

2009-04-29 Thread Timboy
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

Re: Custom primary key

2009-04-29 Thread Malcolm Tredinnick
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

Re: Custom primary key using Oracle 10g

2007-08-20 Thread Catriona
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

Re: Custom primary key using Oracle 10g

2007-08-15 Thread Ian
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

Re: Custom primary key using Oracle 10g

2007-08-15 Thread Catriona
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

Re: Custom primary key using Oracle 10g

2007-08-15 Thread Ian
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

Re: Custom primary key using Oracle 10g

2007-08-14 Thread Catriona
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

Re: Custom primary key using Oracle 10g

2007-08-14 Thread Jon Atkinson
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=