Lesson 4: Testing Related Tables and Deployment
Final testing of related tables functionality, cascade operations, and deploying the Flask application with proper database configuration.
Lesson Objectives
- Test related table functionality with dropdown selections
- Verify cascade delete and update operations work correctly
- Deploy Flask application to Heroku with database configuration
- Troubleshoot deployment issues and validate production functionality
Watch: Testing Related Tables and Deployment
Testing Related Tables and Deployment - Notes
Testing Related Table Functionality
Test all CRUD operations to ensure proper relationship handling between Authors and Books tables.
Key testing areas:
# Test Edit Operations
# 1. Edit author records - verify changes save correctly
# 2. Edit book records - dropdown should show all authors
# 3. Change book's author via dropdown selection
# Test Add Operations
# 1. Add new author with first name, last name
# 2. Add new book - dropdown must contain all existing authors
# 3. Verify new book links to selected author
# Dropdown Requirements
# - Books table: dropdown for author selection (foreign key)
# - Authors table: no dropdown needed (primary table)The key rule: any table with foreign key relationships must use dropdown selections to maintain referential integrity and prevent invalid references.
Cascade Operations
Test cascade operations to ensure database integrity when parent records change.
CASCADE DELETE testing:
# Test deleting an author
# 1. Note which books belong to 'Agatha Christie'
# 2. Delete 'Agatha Christie' from authors table
# 3. Verify all her books are automatically deleted
# 4. Check that no orphaned book records remainCASCADE UPDATE testing:
# Test updating an author
# 1. Edit 'George Orwell' to 'George's Orwell'
# 2. Verify all related book records show updated author name
# 3. Confirm relationship data remains consistentThese cascade behaviors are configured at the database level through foreign key constraints and happen automatically when parent records are modified or deleted.
Deployment Process
Deploy your Flask application with related tables to Heroku following these essential steps.
Pre-deployment cleanup:
# Clean up unnecessary files
git rm kill.py setup.py verify.py
git commit -m "Remove development utility files"
# Commit all changes
git add .
git commit -m "Complete related tables functionality"
git push origin mainHeroku deployment options:
# Manual Deployment:
# 1. Go to Heroku app Deploy tab
# 2. Scroll to Manual deploy section
# 3. Click "Deploy Branch"
# Automatic Deployment:
# 1. Enable "Automatic deploys" in Heroku
# 2. Push changes to GitHub
# 3. Heroku automatically builds and deploysMonitor the build process in Heroku's Activity tab. Each deployment requires a complete build cycle before testing the live application.
Environment Configuration
Configure Heroku environment variables for database connectivity. Missing variables cause deployment failures.
Required Heroku Config Variables:
# Navigate to Heroku app Settings -> Config Vars
# Add these variables from your JawsDB connection string:
HOST=your_database_host
USER=your_database_username
PASSWORD=your_database_password
NAME=your_database_nameCopy values exactly from your JawsDB connection string:
# JawsDB format: mysql://user:password@host:port/database
# Extract each component carefully
# Variable names must match your Flask app expectationsCommon issue: Internal server errors usually indicate missing or incorrect environment variables. Always verify all config vars are set before testing the deployed application.
Troubleshooting Deployment
Systematically troubleshoot deployment issues using Heroku logs and iterative problem-solving.
Check Heroku logs for errors:
# View logs in Heroku dashboard
# 1. Go to app -> More -> View logs
# 2. Look for specific error messages
# 3. Copy error details for analysisCommon deployment issues:
# Internal Server Error
# - Check environment variables are set
# - Verify database connection string
# - Review import statements in base files
# Database Connection Errors
# - Confirm all config vars match JawsDB
# - Check HOST, USER, PASSWORD, NAME values
# - Verify database is accessible
# Base File Issues
# - Remove references to deleted files
# - Update import statements
# - Check route configurationsDeployment iteration cycle: Fix issue → Commit changes → Deploy → Test → Repeat if needed. Each change requires a complete build cycle before testing.
Demo Requirements Summary
Complete Module 4 demo requirements for a functional two-table database application.
Core Requirements:
# Database Structure
# - Two related tables (e.g., Authors and Books)
# - Proper foreign key relationship
# - CASCADE DELETE and UPDATE configured
# User Interface
# - Primary table: standard CRUD operations
# - Secondary table: dropdown for foreign key selection
# - Modal dialogs for edit and delete confirmations
# Functionality Testing
# - Add records to both tables
# - Edit records with dropdown relationships
# - Delete parent records (triggers cascade delete)
# - Update parent records (triggers cascade update)Demo Checklist:
# ✓ Two tables with meaningful relationship
# ✓ Dropdown menus work for foreign key selection
# ✓ Edit functionality preserves relationships
# ✓ Delete operations show confirmation modals
# ✓ Cascade delete removes related records
# ✓ Cascade update maintains data consistency
# ✓ Application deployed and accessible on HerokuFor duplication assignment: Create your own unique two-table relationship with enhanced styling and additional features beyond the basic demo requirements.