question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: Unable to create the django_migrations table (database is locked) - When OUTPUT_DIR to SAMBA share

See original GitHub issue

Hello,

Running ArchiveBox in docker (docker compose) am trying to output my archives to a samba share mounted on the archivebox host.

I am configuring the directories, and the docker-compose.yml file, then running the docker-compose run archivebox init --setup command. Once finished, I’m updating the ArchiveBox.conf file to contain OUTPUT_DIR = /mnt/archivebox (which is where i have my mounted SAMBA share directory mounted to the container from the host using a bind mount), and running the docker-compose up -d command.

In the logs, there is a long pause at [+] Building main SQL index and running initial migrations..., then a failure to load. Full log:

    > /mnt/archivebox
[+] Initializing a new ArchiveBox v0.6.2 collection...
----------------------------------------------------------------------
[+] Building archive folder structure...
    + ./archive, ./sources, ./logs...
    + ./ArchiveBox.conf...
[+] Building main SQL index and running initial migrations...
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/django/db/backends/base/base.py", line 242, in _commit
    return self.connection.commit()
sqlite3.OperationalError: database is locked
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/django/db/migrations/recorder.py", line 68, in ensure_schema
    editor.create_model(self.Migration)
  File "/usr/local/lib/python3.9/site-packages/django/db/backends/sqlite3/schema.py", line 36, in __exit__
    super().__exit__(exc_type, exc_value, traceback)
  File "/usr/local/lib/python3.9/site-packages/django/db/backends/base/schema.py", line 117, in __exit__
    self.atomic.__exit__(exc_type, exc_value, traceback)
  File "/usr/local/lib/python3.9/site-packages/django/db/transaction.py", line 232, in __exit__
    connection.commit()
  File "/usr/local/lib/python3.9/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/django/db/backends/base/base.py", line 266, in commit
    self._commit()
  File "/usr/local/lib/python3.9/site-packages/django/db/backends/base/base.py", line 242, in _commit
    return self.connection.commit()
  File "/usr/local/lib/python3.9/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/usr/local/lib/python3.9/site-packages/django/db/backends/base/base.py", line 242, in _commit
    return self.connection.commit()
django.db.utils.OperationalError: database is locked
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/local/bin/archivebox", line 33, in <module>
    sys.exit(load_entry_point('archivebox', 'console_scripts', 'archivebox')())
  File "/app/archivebox/cli/__init__.py", line 140, in main
    run_subcommand(
  File "/app/archivebox/cli/__init__.py", line 80, in run_subcommand
    module.main(args=subcommand_args, stdin=stdin, pwd=pwd)    # type: ignore
  File "/app/archivebox/cli/archivebox_server.py", line 64, in main
    server(
  File "/app/archivebox/util.py", line 114, in typechecked_function
    return func(*args, **kwargs)
  File "/app/archivebox/main.py", line 1243, in server
    run_subcommand('init', subcommand_args=['--quick'], stdin=None, pwd=out_dir)
  File "/app/archivebox/cli/__init__.py", line 80, in run_subcommand
    module.main(args=subcommand_args, stdin=stdin, pwd=pwd)    # type: ignore
  File "/app/archivebox/cli/archivebox_init.py", line 43, in main

(
  File "/app/archivebox/util.py", line 114, in typechecked_function
    return func(*args, **kwargs)
  File "/app/archivebox/main.py", line 328, in init
    for migration_line in apply_migrations(out_dir):
  File "/app/archivebox/util.py", line 114, in typechecked_function
    return func(*args, **kwargs)
  File "/app/archivebox/index/sql.py", line 138, in apply_migrations
    call_command("migrate", interactive=False, stdout=out)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 168, in call_command
    return command.execute(*args, **defaults)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 85, in wrapped
    res = handle_func(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/commands/migrate.py", line 243, in handle
    post_migrate_state = executor.migrate(
  File "/usr/local/lib/python3.9/site-packages/django/db/migrations/executor.py", line 91, in migrate
    self.recorder.ensure_schema()
  File "/usr/local/lib/python3.9/site-packages/django/db/migrations/recorder.py", line 70, in ensure_schema
    raise MigrationSchemaMissing("Unable to create the django_migrations table (%s)" % exc)
django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table (database is locked)

I have exact setup working succesfully working another machine with ArchiveBox running in docker, but cannot seem to get it to work on this machine (Ubuntu Server 21.10).

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
stephenmetzgercommented, Mar 16, 2022

Not sure why I was getting the issue above, but ended up finding a workaround (probably the ‘right’ way to do it).

I started from scratch and ran a new --setup and docker-compose up with a typical configuration as outlined in the docs to get the package to get the directories and files set up, then edited my docker-compose.yml file to manually mount everything where I wanted it to live. My volumes section under archivebox now looks like this:

            - /mnt/BAlink/archivebox/archive:/data/archive
            - ./archivebox/data/ArchiveBox.conf:/data/ArchiveBox.conf
            - ./archivebox/data/index.sqlite3:/data/index.sqlite3
            - ./archivebox/data/logs:/data/logs
            - ./archivebox/data/sources:/data/sources

Any issues doing it this way?

0reactions
piratecommented, Apr 12, 2022

Note I’ve added a new DB/filesystem troubleshooting area to the wiki that may help people arriving here from Google: https://github.com/ArchiveBox/ArchiveBox/wiki/Upgrading-or-Merging-Archives#database-troubleshooting

Contributions/suggestions welcome there.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to create the django_migrations table (database is ...
Reason : “Database is locked” errors¶. SQLite is meant to be a lightweight database, and thus can't support a high level of concurrency....
Read more >
Digging Deeper Into Django Migrations - Real Python
Django uses a database table called django_migrations . Django automatically creates this table in your database the first time you apply any migrations....
Read more >
Migrations - Django documentation
Migrations are Django's way of propagating changes you make to your models (adding a field, deleting a model, etc.) into your database schema....
Read more >
What really annoys me about Django migrations
Automated database migrations have been a convenient way of dealing with schema changes for a long time in Django.
Read more >
Django Migrations and How to Manage Conflicts
I deploy, create the initial migration and migrate my database. So now, I have the first production server, with two migrations, and the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found