Django

Code

Ticket #6947 (closed: invalid)

Opened 8 months ago

Last modified 4 months ago

Auto increment field in sqlite

Reported by: ctrochalakis Assigned to: nobody
Milestone: Component: Database layer (models, ORM)
Version: SVN Keywords: sqlite
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

When using sqlite3 sql backend the primary key doesn't get the AUTOINCREMENT keyword causing a mess in foreign keys when an object is deleted.

See also the last paragraph of http://www.sqlite.org/faq.html#q1

Attachments

Change History

06/14/08 10:34:46 changed by telenieko

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

Can you elaborate a bit more on the "mess" part? sqlite does not understand AUTOINCREMENT as far as I know, you define a table as INT PRIMARY KEY and sqlite does the same as MS Access does (more or less).

08/08/08 14:29:16 changed by sebastian.hillig <sebastian.hillig@student.hpi.uni-potsdam.de>

  • status changed from new to closed.
  • resolution set to invalid.

Deleting an object via the django-orm will result in deleting related objects. If you delete rows yourself (out of orm-scope) you have to take care of database consistency yourself in case of sqlite (and every other database that doesn't enforce fk consistency) and django would give you a nice error stating that there's something wrong, so please make sure you leave your database consistent. AUTOINCREMENT wouldn't be the solution to any problem since it only enforces one-time use of a primary key. Even if you would be inserting new rows from somewhere else, sqlite would add new rows with largest-pk + 1 as pk up to the point you reach pk == 9223372036854775807, then it would be starting to pick free pks from the beginning. Therefore marking this ticket invalid.


Add/Change #6947 (Auto increment field in sqlite)




Change Properties
Action