#8576: Multiple AutoFields in a model
---------------------------------------+------------------------------------
Reporter: honeyman | Owner: nobody
Status: new | Milestone:
Component: Database wrapper | Version: SVN
Resolution: | Keywords:
Stage: Unreviewed | Has_patch: 1
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
---------------------------------------+------------------------------------
Changes (by ramiro):
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Old description:
> Got the assertions failed recently:
>
> File "C:\Projects\houserules\www\hrdb\events\hrpercustomerobject.py",
> line 14, in <module>
> class HRPerCustomerObject(models.Model):
> File "C:\Projects\houserules\www\hrdb\events\hrpercustomerobject.py",
> line 37, in HRPerCustomerObject
> id_percustomer = models.AutoField ( 'Per-customer ID' )
> File "C:\Projects\houserules\www\django\db\models\fields\__init__.py",
> line 425, in __init__
> assert kwargs.get('primary_key', False) is True, "%ss must have
> primary_key=True." % self.__class__.__name__
> AssertionError: AutoFields must have primary_key=True.
> make: *** [_reset] Error 1
>
> and
>
> File "C:\Projects\houserules\www\django\db\models\options.py", line
> 117, in _prepare
> model.add_to_class('id', auto)
> File "C:\Projects\houserules\www\django\db\models\base.py", line 139,
> in add_to_class
> value.contribute_to_class(cls, name)
> File "C:\Projects\houserules\www\django\db\models\fields\__init__.py",
> line 459, in contribute_to_class
> assert not cls._meta.has_auto_field, "A model can't have more than
> one AutoField."
> AssertionError: A model can't have more than one AutoField.
> make: *** [_reset] Error 1
>
> Depending on the logic and the scenario, it may be really worthy to have
> several AutoFields in a model (for example, when one or both of them in
> some cases is controlled manually), one of which will definitely not be a
> primary key.
> I roughly described one of possible scenarios in
> [http://oebfare.com/logger/django/2008/08/26/ IRC], though this may be
> not the only one.
> Please note that the databases itself do not imply such behaviour
> (auto_increment field in MySQL does not imply a primary key, neither
> SERIAL field in PostgreSQL does), so it is unsafe and overrestrictive to
> add such a limitation in Django.
> The existing documentation on AutoField also does not imply it should be
> used for primary keys only.
>
> My proposal is to withdraw such a limitation; seems that it is only
> required to remove two assert lines from the code�(well, and the related
> tests, of course).
New description:
Got the assertions failed recently:
{{{
File "C:\Projects\houserules\www\hrdb\events\hrpercustomerobject.py",
line 14, in <module>
class HRPerCustomerObject(models.Model):
File "C:\Projects\houserules\www\hrdb\events\hrpercustomerobject.py",
line 37, in HRPerCustomerObject
id_percustomer = models.AutoField ( 'Per-customer ID' )
File "C:\Projects\houserules\www\django\db\models\fields\__init__.py",
line 425, in __init__
assert kwargs.get('primary_key', False) is True, "%ss must have
primary_key=True." % self.__class__.__name__
AssertionError: AutoFields must have primary_key=True.
make: *** [_reset] Error 1
}}}
and
{{{
File "C:\Projects\houserules\www\django\db\models\options.py", line 117,
in _prepare
model.add_to_class('id', auto)
File "C:\Projects\houserules\www\django\db\models\base.py", line 139, in
add_to_class
value.contribute_to_class(cls, name)
File "C:\Projects\houserules\www\django\db\models\fields\__init__.py",
line 459, in contribute_to_class
assert not cls._meta.has_auto_field, "A model can't have more than one
AutoField."
AssertionError: A model can't have more than one AutoField.
make: *** [_reset] Error 1
}}}
Depending on the logic and the scenario, it may be really worthy to have
several AutoFields in a model (for example, when one or both of them in
some cases is controlled manually), one of which will definitely not be a
primary key.
I roughly described one of possible scenarios in
[http://oebfare.com/logger/django/2008/08/26/ IRC], though this may be not
the only one.
Please note that the databases itself do not imply such behaviour
(auto_increment field in MySQL does not imply a primary key, neither
SERIAL field in PostgreSQL does), so it is unsafe and overrestrictive to
add such a limitation in Django.
The existing documentation on AutoField also does not imply it should be
used for primary keys only.
My proposal is to withdraw such a limitation; seems that it is only
required to remove two assert lines from the code�(well, and the related
tests, of course).
Comment:
reformatted description
--
Ticket URL: <http://code.djangoproject.com/ticket/8576#comment:1>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---