id summary reporter owner description type status component version severity resolution keywords cc stage has_patch needs_docs needs_tests needs_better_patch easy ui_ux 31730 manage.py sqlsequencereset not implemented for sqlite3 axil axil "Currently `./manage.py sqlsequencereset` ([https://docs.djangoproject.com/en/3.0/ref/django-admin/#sqlsequencereset docs]) never prints anything for the sqlite3 backend. It happens because the function `sequence_reset_sql` defined in `django/django/db/backends/base/operations.py` is not implemented for the sqlite3 backend in `django/django/db/backends/sqlite3/operations.py` `django/django/contrib/sites/management.py` makes use of this function {{{ # We set an explicit pk instead of relying on auto-incrementation, # so we need to reset the database sequence. See #17415. sequence_sql = connections[using].ops.sequence_reset_sql(no_style(), [Site]) if sequence_sql: if verbosity >= 2: print(""Resetting sequence"") }}} Here `sequence_reset_sql` also does nothing for sqlite3, but sqlite3 is pretty lenient to the sequences, so it didn't result in an exception. Same applies to its usage in `manage.py loaddata`: sqlite3 fixes the sequences automatically. Leniency of sqlite is also the explanation of how `django/tests/backends/tests.py:SequenceResetTest.test_generic_relation` test contrives to pass with `sequence_reset_sql` being noop for sqlite3. What it cannot do automatically is reset the sequence to zero as demonstrated in the new test `django/tests/backends/tests.py:SequenceResetTest.test_reset_sequence` {{{ def test_reset_sequence(self): Post.objects.create(name='1st post', text='hello world') Post.objects.all().delete() # Reset the sequences for the database commands = connections[DEFAULT_DB_ALIAS].ops.sequence_reset_sql(no_style(), [Post]) with connection.cursor() as cursor: for sql in commands: cursor.execute(sql) # If we create a new object now, it should have a PK greater # than the PK we specified manually. obj = Post.objects.create(name='New post', text='goodbye world') self.assertEqual(obj.pk, 1) }}}" Bug assigned Database layer (models, ORM) dev Normal sql sequence reset sqlite3 Accepted 1 0 0 1 0 0