-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

On Tue, Oct 16, 2018 at 10:55:48PM -0700, Rakhee Menon wrote:
> Hi Everyone,
> 
> I have a scenario where one field needs to be a primary key and another 
> field needs to be an AutoField....and Autofield requires a condition 
> primary_key = true
> 
> I get this error 
> django_reports.MstCompositionFm.makeid: (fields.E100) AutoFields must set 
> primary_key=True.
> django_reports.MstSalarystructure: (models.E026) The model cannot have more 
> than one field with 'primary_key=True'
> 
> This is my case:
> 
> icatid = models.BigIntegerField(db_column='ICatID', primary_key=True)
> makedate = models.DateTimeField(db_column='MakeDate') 
> revdate = models.DateTimeField(db_column='RevDate', blank=True, null=True) 
> makeid = models.BigAutoField(db_column='MakeId', primary_key=False)
> 
> It would be of great help if anyone could figure out whats the solution

Hi Rakhee,

By definition, there may only be one primary key per table – primary
key is the unique key that has been chosen as the primary, all other
unique keys are secondary. AutoFields have a requirement that if they
are present in a table, they have to be the primary key of that table,
because that's how auto-increment columns work in certain databases.

What exactly is it that you're after? Do you just want both icatid and
makeid to be unique? If so, set primary_key=True on the AutoField, and
for icatid, just use unique=True instead. That will tell the database
that icatid is a secondary key.

Michal
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAEBCgAGBQJbxyMqAAoJEHA7T/IPM/klo8AP/i83PGOzi7+rwqc566VqdYT9
DY5SF9Vh/NAhCAxNVaC369yXRr2/L2EE0T3mDe9hMv/fSbSp00D25kFwsdLDC5TA
+tIzLN53777mAWFzTIjRhzQuc8usNRvHNcsbfJsaurbX1vm/EObdfjtnTlUzK2z2
KwieFMdbpLOicM7YDHGAGj/wF341blFhu0uDyeHQ6rcrEytaAtcMfPLEE92Ts3YR
qpxGPUwzAbhLOV5xcMsPgT6lnqE8JNxnBjA6DAqxoVk02c2tDoqEiPb71VvPzKdC
OEDxlN4veDSBciuP/ngNHG3kKL7EB5Ce60lo4pAPABhxx8YB6SVJ5gisP6s69j0w
xodELja8zVcrNi0uE0LgnvwS64XG1U5vPSSX6HJzZhozPP2aoP+NZEWcV94IX51O
4BfjWFn45LKLGy+/KENlgvPKMoKSYd9tuTcDFKDmLDb62JIq2ylCFUfj5kdxdZSO
8uMf9ZexQ9Gz604Hbl/xDneUV8k/xu5yfrHk6BX0YRtBxtqIF8E8ZYviqagp2Dw2
Z/zdNSMIGD+j3VxaY7ixGwcHq2svHY/g6AiqUXlA4NuM6KGLO+aWRcjlErryp4gL
q5Kuz5+4UCczpj/qKuNym/6t7BKn51pzX97gZghIVM9A2R5guOW30TB5PCJvgzDN
nOR2s5TXmuVEUdfiOU7d
=D1aU
-----END PGP SIGNATURE-----

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20181017115522.GO18928%40koniiiik.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to