2.9 KiB
Podcastrr Migration Guide
Resolving Common Database Errors
"no such column: podcasts.tags" Error
If you encounter the following error when accessing podcast pages:
sqlite3.OperationalError: no such column: podcasts.tags
This means that your database schema is out of date and missing the tags
column in the podcasts
table. This can happen if you've updated the codebase but haven't run the necessary database migrations.
"no such table: episodes" Error
If you encounter the following error when starting the application:
Error running migration: no such table: episodes
This means that the migration script is trying to modify the episodes table before it has been created. This issue has been fixed in the latest version of the application, which ensures that tables are created before migrations are run.
How to Fix the Issue
Option 1: Run the Migration Script
The simplest way to fix this issue is to run the provided migration script:
python run_migrations.py
This script will run all necessary migrations, including adding the tags
column to the podcasts
table.
Option 2: Reinitialize the Database
If you're still having issues, you can reinitialize the database:
python init_db.py
This will create all tables and run all migrations. Note that this will preserve your existing data.
Understanding Migrations in Podcastrr
Podcastrr uses a simple migration system to update the database schema when new features are added. Migrations are stored in the migrations
directory and are automatically run when:
- The application starts (via
application.py
) - The database is initialized (via
init_db.py
) - The migration script is run (via
run_migrations.py
)
Adding New Migrations
If you need to add a new migration:
- Create a new Python file in the
migrations
directory (e.g.,add_new_feature.py
) - Implement a
run_migration()
function that makes the necessary database changes - The migration will be automatically discovered and run by the application
Example migration structure:
"""
Migration script to add a new feature.
"""
import sqlite3
from flask import current_app
def run_migration():
"""
Run the migration to add the new feature.
"""
# Get the database path
db_path = current_app.config['SQLALCHEMY_DATABASE_URI'].replace('sqlite:///', '')
# Connect to the database
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
# Make database changes
# ...
# Commit and close
conn.commit()
conn.close()
print("Migration completed successfully!")
return True
Troubleshooting
If you're still experiencing issues after running the migrations:
- Check the application logs for detailed error messages
- Verify that the database file exists and is accessible
- Ensure that the migration scripts are in the correct location
- Try restarting the application after running the migrations