The latest migrations added in this PR #516 produce data lost in the database.
Since SQLite does not support changing the table schema you have to
- create a new table
- copy data from the old table to the new table
- drop the old table
When you drop the old table an implicit DELETE query is executed for the master table and it triggers DELETE queries for secondary tables that contain foreign keys to the primary table torrust_torrents with ON DELETE CASCADE
The official documentation about DROP is not clear (at least for me). In this site it explains the problem.
However, if the foreign key constraint is defined with ON DELETE CASCADE, then the parent table will be dropped, and any rows that reference that table’s primary key column will be deleted in the child table.
We have to change the migration to avoid deleting secondary tables.
Links