Django db_table_comment with sqlite database

It seems that I have found a bug in all 4.2+ versions of Django (including main branch and 5.0rc). I made a repo with steps to reproduce and full description of the bug – GitHub - FeroxTL/django-sqlite-bug . Long story short: sqlite does not support comments, but when you change (not create) Meta.db_table_comment sqlite backend django.db.backends.sqlite3.schema.DatabaseSchemaEditor tries to generate COMMENT sql and it obviously falls.

$./ migrate
System check identified some issues:

question.QuestionThree: (models.W046) SQLite does not support comments on tables (db_table_comment).
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, question, sessions
Running migrations:
  Applying question.0001_initial... OK
  Applying question.0002_alter_questionthree_table_comment...Traceback (most recent call last):
  File "env/lib/python3.10/site-packages/django/db/backends/", line 89, in _execute
    return self.cursor.execute(sql, params)
  File "env/lib/python3.10/site-packages/django/db/backends/sqlite3/", line 328, in execute
    return super().execute(query, params)
sqlite3.OperationalError: near "COMMENT": syntax error

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "proj/./", line 22, in <module>
  File "proj/./", line 18, in main
  File "env/lib/python3.10/site-packages/django/core/management/", line 442, in execute_from_command_line
  File "env/lib/python3.10/site-packages/django/core/management/", line 436, in execute
  File "env/lib/python3.10/site-packages/django/core/management/", line 412, in run_from_argv
    self.execute(*args, **cmd_options)
  File "env/lib/python3.10/site-packages/django/core/management/", line 458, in execute
    output = self.handle(*args, **options)
  File "env/lib/python3.10/site-packages/django/core/management/", line 106, in wrapper
    res = handle_func(*args, **kwargs)
  File "env/lib/python3.10/site-packages/django/core/management/commands/", line 356, in handle
    post_migrate_state = executor.migrate(
  File "env/lib/python3.10/site-packages/django/db/migrations/", line 135, in migrate
    state = self._migrate_all_forwards(
  File "env/lib/python3.10/site-packages/django/db/migrations/", line 167, in _migrate_all_forwards
    state = self.apply_migration(
  File "env/lib/python3.10/site-packages/django/db/migrations/", line 252, in apply_migration
    state = migration.apply(state, schema_editor)
  File "env/lib/python3.10/site-packages/django/db/migrations/", line 132, in apply
  File "env/lib/python3.10/site-packages/django/db/migrations/operations/", line 610, in database_forwards
  File "env/lib/python3.10/site-packages/django/db/backends/base/", line 640, in alter_db_table_comment
  File "env/lib/python3.10/site-packages/django/db/backends/base/", line 201, in execute
    cursor.execute(sql, params)
  File "env/lib/python3.10/site-packages/django/db/backends/", line 102, in execute
    return super().execute(sql, params)
  File "env/lib/python3.10/site-packages/django/db/backends/", line 67, in execute
    return self._execute_with_wrappers(
  File "env/lib/python3.10/site-packages/django/db/backends/", line 80, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "env/lib/python3.10/site-packages/django/db/backends/", line 84, in _execute
    with self.db.wrap_database_errors:
  File "env/lib/python3.10/site-packages/django/db/", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "env/lib/python3.10/site-packages/django/db/backends/", line 89, in _execute
    return self.cursor.execute(sql, params)
  File "env/lib/python3.10/site-packages/django/db/backends/sqlite3/", line 328, in execute
    return super().execute(query, params)
django.db.utils.OperationalError: near "COMMENT": syntax error
1 Like

Please use the bug tracker at

Can you share you model codes . . .?


from django.db import models

class QuestionThree(models.Model):

    class Meta:
        db_table_comment = "Table comment 2"

I think this has to do with django version Django==4.2.7. Please check this repo

Here it worked just fine and here are requirements Django==4.2.8