relation "payment_provider_configs" already existsmigration was previously applied but is missingmigration was previously applied but has been modified
Your database has tables from migrations, but the migration tracking table (_sqlx_migrations) is out of sync with the actual database state.
# 1. Drop and recreate the database
dropdb aframp
createdb aframp
# 2. Run setup script
./setup.shIf you have important data and want to keep it:
# Check what tables exist
psql -d aframp -c "\dt"
# Check migration tracking
psql -d aframp -c "SELECT * FROM _sqlx_migrations ORDER BY version;"# Clear the migration tracking
psql -d aframp -c "DELETE FROM _sqlx_migrations;"
# Manually insert migration records (adjust checksums as needed)
psql -d aframp << 'EOF'
-- Mark migration 1 as applied
INSERT INTO _sqlx_migrations (version, description, success, checksum, execution_time, installed_on)
VALUES (20260122120000, 'create core schema', true,
(SELECT checksum FROM (VALUES (E'\\x' || encode(sha256(pg_read_file('migrations/20260122120000_create_core_schema.sql')::bytea), 'hex'))) AS t(checksum)),
0, now());
-- Mark migration 2 as applied
INSERT INTO _sqlx_migrations (version, description, success, checksum, execution_time, installed_on)
VALUES (20260123040000, 'implement payments schema', true,
(SELECT checksum FROM (VALUES (E'\\x' || encode(sha256(pg_read_file('migrations/20260123040000_implement_payments_schema.sql')::bytea), 'hex'))) AS t(checksum)),
0, now());
-- Mark migration 3 as applied
INSERT INTO _sqlx_migrations (version, description, success, checksum, execution_time, installed_on)
VALUES (20260124000000, 'indexes and constraints', true,
(SELECT checksum FROM (VALUES (E'\\x' || encode(sha256(pg_read_file('migrations/20260124000000_indexes_and_constraints.sql')::bytea), 'hex'))) AS t(checksum)),
0, now());
EOF# Use the simpler approach - just mark them with dummy checksums
./fix-migrations-simple.shIf you just want to get the server running:
# Start the server without running migrations
cargo run --features databaseThe server will work with the existing database schema.
To avoid this issue in the future:
Always use migrations for schema changes.
If a migration fails partway through, you need to:
- Fix the migration file
- Rollback the partial changes
- Re-run the migration
Commit migration files to git and never modify them after they've been applied.
- Development:
aframp - Testing:
aframp_test - Production:
aframp_prod
I've created a simple script to fix the migration state:
#!/bin/bash
# fix-migrations-simple.sh
DB_NAME="aframp"
echo "Fixing migration state for $DB_NAME..."
# Clear existing migration records
psql -d "$DB_NAME" -c "DELETE FROM _sqlx_migrations;"
# Add migration records with dummy checksums
psql -d "$DB_NAME" << 'EOF'
INSERT INTO _sqlx_migrations (version, description, success, checksum, execution_time, installed_on)
VALUES
(20260122120000, 'create core schema', true, E'\\x00', 0, now()),
(20260123040000, 'implement payments schema', true, E'\\x00', 0, now()),
(20260124000000, 'indexes and constraints', true, E'\\x00', 0, now());
EOF
echo "✅ Migration state fixed!"
echo ""
echo "⚠️ Note: Checksums are set to dummy values."
echo "This means sqlx will think migrations have been modified."
echo "This is OK for development, but for production, use proper checksums."Save this as fix-migrations-simple.sh, make it executable, and run it:
chmod +x fix-migrations-simple.sh
./fix-migrations-simple.shThis table tracks which migrations have been applied to your database. Each row contains:
version: Migration timestamp (e.g., 20260122120000)description: Human-readable descriptionchecksum: Hash of the migration file contentsuccess: Whether it applied successfully
sqlx compares the checksum of the migration file with the stored checksum to detect if a migration file has been modified after being applied. This prevents accidental schema corruption.
- Editing a migration file after it's been applied
- Copying migrations from another project
- Git merge conflicts in migration files
- Manual database changes that don't match the migration
- Create a new migration:
sqlx migrate add description_here - Edit the migration file
- Test it:
sqlx migrate run - If it fails, fix and re-run
- Once working, commit to git
- Never edit the migration file again
- Create a NEW migration
- Don't edit old migrations
- Use the new migration to modify the schema
# Quick reset script
dropdb aframp && createdb aframp && sqlx migrate runYour database has:
- ✅ All tables created
- ✅ All indexes created
- ❌ Migration tracking out of sync
Recommended Action: Use Option 1 (Fresh Start) if you don't have important data, or use the fix-migrations-simple.sh script if you want to keep your data.