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

sqlite3 Drop() attempts to drop internal tables which might fail f.e. for sqlite_sequence #1138

Open
makadev opened this issue Aug 23, 2024 · 0 comments · May be fixed by #1172
Open

sqlite3 Drop() attempts to drop internal tables which might fail f.e. for sqlite_sequence #1138

makadev opened this issue Aug 23, 2024 · 0 comments · May be fixed by #1172

Comments

@makadev
Copy link

makadev commented Aug 23, 2024

As per Documentation if there is an AUTOINCREMENT column sqlite creates an internal table called sqlite_sequence. This table can't be dropped.

Using Drop() with the sqlite3 migration driver simply attempts do delete every table found in sqlite_master

query := `SELECT name FROM sqlite_master WHERE type = 'table';`

This leads to the error "table sqlite_sequence may not be dropped" if AUTOINCREMENT fields are used and records created.
In general it might be best to ignore tables starting with sqlite_ since they can not be created using create table and probably don't need to be deleted. In case of sqlite_sequence sqlite will remove entries entries if the respective table is removed so there is no need for any cleanup either. That's probably the same for the sqlite_stat* tables created by ANALYZE and so on.

The query for the tables to be dropped could look like this:
SELECT name FROM sqlite_master WHERE type = 'table' and name not like 'sqlite_%';

@makadev makadev changed the title sqlite3 Drop() attempts to drop interal tables which might fail f.e. for sqlite_sequence sqlite3 Drop() attempts to drop internal tables which might fail f.e. for sqlite_sequence Aug 23, 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
Development

Successfully merging a pull request may close this issue.

1 participant