Well, according to "If there's some really strong use-case that's been
overlooked here, it can be brought up in a thread on django-dev", I
think I need to explain the feature a bit better.
Why we may ever need to have autofields being non-primary-keys?
To be able to use several autofields in a single model.
Django is optimized for the common case. Sure, it may well be that
it's easy to accommodate uncommon cases as well, and when it's
reasonable, we should definitely do so, but the reason it hasn't been
up to this point is simply that not enough people need it. I highly
doubt any of the core developers were actively seeking to restrict
people from using non-primary-key auto-incrementing fields; Django was
simply written to address the vastly most common need.
> Second, is the use case where the primary key is not an AutoField but
> the record insert order needs to be tracked. For instance, if the
> primary key is a phone number or UUIDField it would be useful to also
> have an AutoField so that records can be sorted in the order they were
> inserted into the table. This is a real world problem I am faced with
> right now.
Call me crazy, but why would an AutoField help you with that? Since
you later explain that the records are created in satellite systems,
then aggregated, wouldn't you still run into problems ordering by
something that's generated in isolation? It sounds like what you
really want is a DateTimeField(default=datetime.datetime.now). That
way, you get orderable fields that can be combined from any number of
sources without worrying about collisions. Plus, you get the added
bonus of having a real-world value that you can use for more than just
ordering.
Mind you, I'm not trying to say that a non-pk AutoField is a bad idea
in itself. I'm just not convinced that this use case is a very good
justification.
-Gul
The limitation in Oracle is in the backend, not in the database. To
support an AutoField, we create a sequence and a trigger, the names of
which are derived from the name of the table. To support multiple
AutoFields, the names would have to be distinct -- most likely they
would be derived from a combination of the names of the table and the
column. But for backward compatibility, the backend needs to continue
to generate the same sequence name when the model has only one
AutoField. That's not impossible, but the refactoring necessary to
meet both of those goals is not trivial.
Regards,
Ian
> I'll note that if the AutoField is defined with unique=True the table create
> works.
but On Mar 3, 6:19 pm, NewSpire <newsp...@gmail.com> wrote:
>
> Crazy Gul, ;-) the order of the records, in my case, is only
> important in the context of a foreign in key. The records in this
> table are grouped based on records in another table. I only need the
> correct order for the group, not the entire table or aggregated
> tables.
So -- you can't put a unique index on your auto-field.
There is one point that is unclear to me from the discussion so far -- are
your servers symmetric? Because if there are separate "sattelites"
and "aggregators", then you really have two different models: Satellites with
Auto pk=order & unique UUID, and aggregators with pk=UUID & unrestricted
order field.