Extract columns cannot create foreign key relation: sqlite3.OperationalError: table sqlite_master may not be modified
See original GitHub issueThanks for what seems like a truly great suite of libraries. I wanted to try out Datasette, but never got more than half way through your YouTube video with the SF tree dataset. Whenever I try to extract a column, I get a sqlite3.OperationalError: table sqlite_master may not be modified
error from Python. This snippet reproduces the error on my system, Python 3.9.1 and sqlite-utils 3.5 on an M1 Macbook Pro running in rosetta mode:
curl "https://data.nasa.gov/resource/y77d-th95.json" | \
sqlite-utils insert meteorites.db meteorites - --pk=id
sqlite-utils extract meteorites.db meteorites recclass
I have tried googling the problem, but all I’ve found is that this might be a problem with the sqlite3 database running in defensive mode, but I definitely can’t know for sure. Does the problem seem familiar to you?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:8
Top Results From Across the Web
android - SQLite Foreign Key - Stack Overflow
You tried to create FK on non-existing column and this is reason why it doesn't work. So you need to add this: checklist_id...
Read more >sqlite_utils Python library — sqlite-utils 3.15 documentation
Custom column order and column types; Explicitly creating a table; Compound primary keys; Specifying foreign keys. Table configuration options; Setting ...
Read more >sqlite3 — DB-API 2.0 interface for SQLite databases — Python ...
Call sqlite3.connect() to to create a connection to the database tutorial.db in the current working directory, implicitly creating it if it does not...
Read more >SQLite Foreign Key Support
In order to use foreign key constraints in SQLite, the library must be compiled with neither SQLITE_OMIT_FOREIGN_KEY nor SQLITE_OMIT_TRIGGER ...
Read more >#29182 (SQLite 3.26 breaks database migration ForeignKey ...
This happens only when running SQLite DB migrations from management command under transaction. Running migrations via ./manage.py migrate does not cause any ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This bug affects me as well. Env:
Similar to @mdrovdahl, I was able to work around this bug by piping the SQL string constructed in
add_foreign_keys
to thesqlite3
command itself. Specifically, if you’re trying to patch this yourself, replace lines 1026-1039 of db.py in your site packages with something similar to the following:Then from your terminal:
db-to-sqlite "<connection string>" your.db --all > output.sql && sqlite3 your.db < output.sql
If you want to run this with
-p
, you’ll have to actually open a file in code to write to instead of redirecting the output.A related historical problem:
https://github.com/tekartik/sqflite/issues/525#issuecomment-714500720
I wonder if the version of Sqlite or Python for Intel chip have defensive mode disabled by default, whereas M1 chips versions have it enabled.