Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: django.db.utils.OperationalError: no such column: django_migrations.id #17815

Closed
wants to merge 1 commit into from

Conversation

milahu
Copy link

@milahu milahu commented Feb 3, 2024

i got this error when running archivebox

error stack
Traceback (most recent call last):
  File "/nix/store/i4xn2l7r4a1md2xcma1xkm812wci1fky-python3.11-Django-4.2.9/lib/python3.11/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/i4xn2l7r4a1md2xcma1xkm812wci1fky-python3.11-Django-4.2.9/lib/python3.11/site-packages/django/db/backends/sqlite3/base.py", line 328, in execute
    return super().execute(query, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sqlite3.OperationalError: no such column: django_migrations.id

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

Traceback (most recent call last):
  File "/nix/store/i4xn2l7r4a1md2xcma1xkm812wci1fky-python3.11-Django-4.2.9/lib/python3.11/site-packages/django/db/migrations/executor.py", line 254, in apply_migration
    self.record_migration(migration)
  File "/nix/store/i4xn2l7r4a1md2xcma1xkm812wci1fky-python3.11-Django-4.2.9/lib/python3.11/site-packages/django/db/migrations/executor.py", line 269, in record_migration
    self.recorder.record_applied(migration.app_label, migration.name)
  File "/nix/store/i4xn2l7r4a1md2xcma1xkm812wci1fky-python3.11-Django-4.2.9/lib/python3.11/site-packages/django/db/migrations/recorder.py", line 94, in record_applied
    self.migration_qs.create(app=app, name=name)
  File "/nix/store/i4xn2l7r4a1md2xcma1xkm812wci1fky-python3.11-Django-4.2.9/lib/python3.11/site-packages/django/db/models/query.py", line 658, in create
    obj.save(force_insert=True, using=self.db)
  File "/nix/store/i4xn2l7r4a1md2xcma1xkm812wci1fky-python3.11-Django-4.2.9/lib/python3.11/site-packages/django/db/models/base.py", line 814, in save
    self.save_base(
  File "/nix/store/i4xn2l7r4a1md2xcma1xkm812wci1fky-python3.11-Django-4.2.9/lib/python3.11/site-packages/django/db/models/base.py", line 877, in save_base
    updated = self._save_table(
              ^^^^^^^^^^^^^^^^^
  File "/nix/store/i4xn2l7r4a1md2xcma1xkm812wci1fky-python3.11-Django-4.2.9/lib/python3.11/site-packages/django/db/models/base.py", line 1020, in _save_table
    results = self._do_insert(
              ^^^^^^^^^^^^^^^^
  File "/nix/store/i4xn2l7r4a1md2xcma1xkm812wci1fky-python3.11-Django-4.2.9/lib/python3.11/site-packages/django/db/models/base.py", line 1061, in _do_insert
    return manager._insert(
           ^^^^^^^^^^^^^^^^
  File "/nix/store/i4xn2l7r4a1md2xcma1xkm812wci1fky-python3.11-Django-4.2.9/lib/python3.11/site-packages/django/db/models/manager.py", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/i4xn2l7r4a1md2xcma1xkm812wci1fky-python3.11-Django-4.2.9/lib/python3.11/site-packages/django/db/models/query.py", line 1805, in _insert
    return query.get_compiler(using=using).execute_sql(returning_fields)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/i4xn2l7r4a1md2xcma1xkm812wci1fky-python3.11-Django-4.2.9/lib/python3.11/site-packages/django/db/models/sql/compiler.py", line 1822, in execute_sql
    cursor.execute(sql, params)
  File "/nix/store/i4xn2l7r4a1md2xcma1xkm812wci1fky-python3.11-Django-4.2.9/lib/python3.11/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/i4xn2l7r4a1md2xcma1xkm812wci1fky-python3.11-Django-4.2.9/lib/python3.11/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
    return executor(sql, params, many, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/i4xn2l7r4a1md2xcma1xkm812wci1fky-python3.11-Django-4.2.9/lib/python3.11/site-packages/django/db/backends/utils.py", line 84, in _execute
    with self.db.wrap_database_errors:
  File "/nix/store/i4xn2l7r4a1md2xcma1xkm812wci1fky-python3.11-Django-4.2.9/lib/python3.11/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/nix/store/i4xn2l7r4a1md2xcma1xkm812wci1fky-python3.11-Django-4.2.9/lib/python3.11/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/i4xn2l7r4a1md2xcma1xkm812wci1fky-python3.11-Django-4.2.9/lib/python3.11/site-packages/django/db/backends/sqlite3/base.py", line 328, in execute
    return super().execute(query, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django.db.utils.OperationalError: no such column: django_migrations.id

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

Traceback (most recent call last):
  File "/nix/store/ry2xibh8xwwiazjryd4lh1sa2zgfs9ib-archivebox-0.7.2/bin/.archivebox-wrapped", line 9, in <module>
    sys.exit(main())
             ^^^^^^
  File "/nix/store/ry2xibh8xwwiazjryd4lh1sa2zgfs9ib-archivebox-0.7.2/lib/python3.11/site-packages/archivebox/cli/__init__.py", line 140, in main
    run_subcommand(
  File "/nix/store/ry2xibh8xwwiazjryd4lh1sa2zgfs9ib-archivebox-0.7.2/lib/python3.11/site-packages/archivebox/cli/__init__.py", line 80, in run_subcommand
    module.main(args=subcommand_args, stdin=stdin, pwd=pwd)    # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/ry2xibh8xwwiazjryd4lh1sa2zgfs9ib-archivebox-0.7.2/lib/python3.11/site-packages/archivebox/cli/archivebox_init.py", line 43, in main
    init(
  File "/nix/store/ry2xibh8xwwiazjryd4lh1sa2zgfs9ib-archivebox-0.7.2/lib/python3.11/site-packages/archivebox/util.py", line 116, in typechecked_function
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/ry2xibh8xwwiazjryd4lh1sa2zgfs9ib-archivebox-0.7.2/lib/python3.11/site-packages/archivebox/main.py", line 366, in init
    for migration_line in apply_migrations(out_dir):
                          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/ry2xibh8xwwiazjryd4lh1sa2zgfs9ib-archivebox-0.7.2/lib/python3.11/site-packages/archivebox/util.py", line 116, in typechecked_function
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/ry2xibh8xwwiazjryd4lh1sa2zgfs9ib-archivebox-0.7.2/lib/python3.11/site-packages/archivebox/index/sql.py", line 146, in apply_migrations
    call_command("migrate", interactive=False, stdout=out)
  File "/nix/store/i4xn2l7r4a1md2xcma1xkm812wci1fky-python3.11-Django-4.2.9/lib/python3.11/site-packages/django/core/management/__init__.py", line 194, in call_command
    return command.execute(*args, **defaults)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/i4xn2l7r4a1md2xcma1xkm812wci1fky-python3.11-Django-4.2.9/lib/python3.11/site-packages/django/core/management/base.py", line 458, in execute
    output = self.handle(*args, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/i4xn2l7r4a1md2xcma1xkm812wci1fky-python3.11-Django-4.2.9/lib/python3.11/site-packages/django/core/management/base.py", line 106, in wrapper
    res = handle_func(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/i4xn2l7r4a1md2xcma1xkm812wci1fky-python3.11-Django-4.2.9/lib/python3.11/site-packages/django/core/management/commands/migrate.py", line 356, in handle
    post_migrate_state = executor.migrate(
                         ^^^^^^^^^^^^^^^^^
  File "/nix/store/i4xn2l7r4a1md2xcma1xkm812wci1fky-python3.11-Django-4.2.9/lib/python3.11/site-packages/django/db/migrations/executor.py", line 135, in migrate
    state = self._migrate_all_forwards(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/i4xn2l7r4a1md2xcma1xkm812wci1fky-python3.11-Django-4.2.9/lib/python3.11/site-packages/django/db/migrations/executor.py", line 167, in _migrate_all_forwards
    state = self.apply_migration(
            ^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/i4xn2l7r4a1md2xcma1xkm812wci1fky-python3.11-Django-4.2.9/lib/python3.11/site-packages/django/db/migrations/executor.py", line 249, in apply_migration
    with self.connection.schema_editor(
  File "/nix/store/i4xn2l7r4a1md2xcma1xkm812wci1fky-python3.11-Django-4.2.9/lib/python3.11/site-packages/django/db/backends/sqlite3/schema.py", line 40, in __exit__
    self.connection.check_constraints()
  File "/nix/store/i4xn2l7r4a1md2xcma1xkm812wci1fky-python3.11-Django-4.2.9/lib/python3.11/site-packages/django/db/backends/sqlite3/base.py", line 244, in check_constraints
    violations = cursor.execute("PRAGMA foreign_key_check").fetchall()
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/i4xn2l7r4a1md2xcma1xkm812wci1fky-python3.11-Django-4.2.9/lib/python3.11/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/i4xn2l7r4a1md2xcma1xkm812wci1fky-python3.11-Django-4.2.9/lib/python3.11/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
    return executor(sql, params, many, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/i4xn2l7r4a1md2xcma1xkm812wci1fky-python3.11-Django-4.2.9/lib/python3.11/site-packages/django/db/backends/utils.py", line 83, in _execute
    self.db.validate_no_broken_transaction()
  File "/nix/store/i4xn2l7r4a1md2xcma1xkm812wci1fky-python3.11-Django-4.2.9/lib/python3.11/site-packages/django/db/backends/base/base.py", line 531, in validate_no_broken_transaction
    raise TransactionManagementError(
django.db.transaction.TransactionManagementError: An error occurred in the current transaction. You can't execute queries until the end of the 'atomic' block.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello! Thank you for your contribution 💪

As it's your first contribution be sure to check out the patch review checklist.

If you're fixing a ticket from Trac make sure to set the "Has patch" flag and include a link to this PR in the ticket!

If you have any design or process questions then you can ask in the Django forum.

Welcome aboard ⛵️!

@felixxm
Copy link
Member

felixxm commented Feb 3, 2024

Thanks for this patch, however there is nothing to fix here. Implicit id is added automatically to all models. If you're having trouble understanding how Django works, see TicketClosingReasons/UseSupportChannels for ways to get help.

@felixxm felixxm closed this Feb 3, 2024
@milahu
Copy link
Author

milahu commented Feb 3, 2024

Implicit id is added automatically to all models

then why do i get the error no such column: django_migrations.id

then why is the error fixed by my patch

im pretty sure that the select id, ... from django_migrations query
is caused by django, and not by my app (archivebox)

@felixxm
Copy link
Member

felixxm commented Feb 3, 2024

This is not a proper place for support questions, see TicketClosingReasons/UseSupportChannels for ways to get help.

@milahu
Copy link
Author

milahu commented Feb 3, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants