I actually wasn't aware of AutoField until just now, and thought that
primary keys not being made auto increment was by design for some reason.
--
Ticket URL: <https://code.djangoproject.com/ticket/23748>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* needs_better_patch: => 0
* resolution: => invalid
* needs_tests: => 0
* needs_docs: => 0
Comment:
None of the Django core backends support `AutoField` introspection yet.
However, `inspectdb` should add a hint as a comment (`# AutoField?`) in
the resulting output. Apparently, it's the best we can do currently.
If you think you can add `AutoField` introspection in some Django core
backend or if the comment mentioned above is not present, feel free to
reopen the ticket with some more information.
--
Ticket URL: <https://code.djangoproject.com/ticket/23748#comment:1>
Comment (by paulcdejean):
Replying to [comment:1 claudep]:
> None of the Django core backends support `AutoField` introspection yet.
However, `inspectdb` should add a hint as a comment (`# AutoField?`) in
the resulting output. Apparently, it's the best we can do currently.
>
> If you think you can add `AutoField` introspection in some Django core
backend or if the comment mentioned above is not present, feel free to
reopen the ticket with some more information.
Which core backends don't support autofield introspection?
--
Ticket URL: <https://code.djangoproject.com/ticket/23748#comment:2>
Comment (by claudep):
There is a `can_introspect_autofield` flag set to `False` in
`django/db/backends/__init__.py`, and this flag is not set anywhere else
(see c89d80e2cc9bf1f401aa3af4047bdc6f3dc5bfa4). I'm not saying that core
backends *cannot* introspect `AutoField`, but currently none of them
implement the needed discovery code.
--
Ticket URL: <https://code.djangoproject.com/ticket/23748#comment:3>
* status: closed => new
* resolution: invalid =>
* component: Utilities => Database layer (models, ORM)
* type: Uncategorized => New feature
* stage: Unreviewed => Someday/Maybe
Comment:
Opening this for if someone wants to implement the introspection. (Though,
it's not a bug.)
--
Ticket URL: <https://code.djangoproject.com/ticket/23748#comment:4>
* has_patch: 0 => 1
* stage: Someday/Maybe => Accepted
Comment:
PR for MySQL and PostgreSQL: https://github.com/django/django/pull/3579
--
Ticket URL: <https://code.djangoproject.com/ticket/23748#comment:5>
Comment (by Claude Paroz <claude@…>):
In [changeset:"11662022be261d9a926b763e9fecc9f55ac3514a"]:
{{{
#!CommitTicketReference repository=""
revision="11662022be261d9a926b763e9fecc9f55ac3514a"
Added AutoField introspection for MySQL
Refs #23748.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23748#comment:6>
Comment (by Claude Paroz <claude@…>):
In [changeset:"1a63093e22a18688914a82651c461e2ea89cd564"]:
{{{
#!CommitTicketReference repository=""
revision="1a63093e22a18688914a82651c461e2ea89cd564"
Added AutoField introspection for PostgreSQL
Refs #23748.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23748#comment:7>
* has_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/23748#comment:8>
* version: 1.7 => master
Comment:
In
[https://github.com/django/django/commit/9af6c97504ef2b06dd5292d03ea94d3eb5d8c4d6
9af6c97504ef2b06dd5292d03ea94d3eb5d8c4d6]
Added AutoField introspection on Oracle.
--
Ticket URL: <https://code.djangoproject.com/ticket/23748#comment:9>
Comment (by Tim Graham):
It looks like the remaining task for this ticket is to add introspection
on SQLite (if the column definition includes AUTOINCREMENT).
--
Ticket URL: <https://code.djangoproject.com/ticket/23748#comment:10>
Comment (by Nick Pope):
Replying to [comment:10 Tim Graham]:
> It looks like the remaining task for this ticket is to add introspection
on SQLite (if the column definition includes AUTOINCREMENT).
So I've looked into rounding out the introspection support for AutoField -
here is a [https://github.com/django/django/pull/10825 PR] for SQLite.
It really turns out to be quite simple. According to the documentation
`AUTOINCREMENT` can only be used with `INTEGER PRIMARY KEY` which is
automatically an alias of `ROWID` that actually provides unique
incremented values. `AUTOINCREMENT` merely changes the algorithm used, but
is usually not necessary and ought to be avoided. See
[https://www.sqlite.org/autoinc.html here] and
[https://www.sqlite.org/lang_createtable.html#rowid here] for details.
There are two things to be aware of:
1. It is not possible to introspect `BigAutoField` as `BIGINT PRIMARY KEY`
cannot have `AUTOINCREMENT` and does not alias `ROWID`. I disabled the
test for SQLite.
2. No effort is made to check for composite primary keys, but I don't
think we do for other backends. We just assume the first `INTEGER PRIMARY
KEY` column is the `AutoField`.
--
Ticket URL: <https://code.djangoproject.com/ticket/23748#comment:11>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/23748#comment:12>
* owner: nobody => Nick Pope
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/23748#comment:13>
Comment (by Tim Graham <timograham@…>):
In [changeset:"a35d2a4510d5beec398b1007aaa26492d6aedf97" a35d2a45]:
{{{
#!CommitTicketReference repository=""
revision="a35d2a4510d5beec398b1007aaa26492d6aedf97"
Refs #23748 -- Added AutoField introspection for SQLite.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23748#comment:14>
* status: assigned => closed
* resolution: => fixed
--
Ticket URL: <https://code.djangoproject.com/ticket/23748#comment:15>