simonw / db-to-sqlite

CLI tool for exporting tables or queries from any SQL database to a SQLite file
Apache License 2.0
370 stars 29 forks source link

sqlite3.OperationalError: table sqlite_master may not be modified #45

Open PanosDine opened 1 year ago

PanosDine commented 1 year ago

I get the following error when I try to use the db-to-sqlite command to export my postgres db into a .db file: sqlite3.OperationalError: table sqlite_master may not be modified

I'm using db-to-sqlite 1.4, sqlite-utils 3.30, and Python 3.10.8. I installed db-to-sqlite with pip install 'db-to-sqlite[postgresql]'.

My command is something like: db-to-sqlite "postgresql://localhost/my_db" my_exported_db.db --all --skip=django_migrations

Traceback:

File "/Users/user/.virtualenvs/myproject/bin/db-to-sqlite", line 8, in <module>
    sys.exit(cli())
  File "/Users/user/.virtualenvs/myproject/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/Users/user/.virtualenvs/myproject/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/Users/user/.virtualenvs/myproject/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/user/.virtualenvs/myproject/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/Users/user/.virtualenvs/myproject/lib/python3.10/site-packages/db_to_sqlite/cli.py", line 166, in cli
    db.add_foreign_keys(foreign_keys_to_add_final)
  File "/Users/user/.virtualenvs/myproject/lib/python3.10/site-packages/sqlite_utils/db.py", line 1096, in add_foreign_keys
    cursor.execute(
sqlite3.OperationalError: table sqlite_master may not be modified

The only workaround I found online was this comment by awpears, but that means overwriting the db.py file