drop-table Command

Remove existing database tables using the Akron CLI across SQLite, MySQL, PostgreSQL, and MongoDB.

Overview

The drop-table command removes existing tables from your database. This is a destructive operation that permanently deletes the table and all its data. Use with caution.

Basic Syntax

akron drop-table <table_name> --db <database_url>

⚠️ Warning

This command permanently deletes the table and all its data. Make sure to backup your data before running this command.

Parameters

table_name

Type: str (required)

Name of the table to drop. Must exist in the target database.

--db

Type: str (required)

Database connection URL. Supports sqlite://, mysql://, postgres://, and mongodb:// schemes.

--force

Type: flag (optional)

Skip confirmation prompt and force table deletion.

Examples

SQLite

1# Drop table with confirmation
2akron drop-table users --db "sqlite:///./myapp.db"
3
4# Force drop without confirmation
5akron drop-table sessions --db "sqlite:///./myapp.db" --force
Expected Output
Are you sure you want to drop table 'users'? (y/N): y
✓ Table 'users' dropped successfully from SQLite database

MySQL

1# Drop table from MySQL database
2akron drop-table products --db "mysql://user:password@localhost:3306/store"
3
4# Drop with force flag
5akron drop-table temp_data --db "mysql://user:pass@host:3306/app" --force
Expected Output
✓ Table 'products' dropped successfully from MySQL database
✓ All data has been permanently deleted

PostgreSQL

1# Drop table from PostgreSQL
2akron drop-table orders --db "postgres://user:password@localhost:5432/ecommerce"
3
4# Drop with SSL connection
5akron drop-table logs --db "postgres://user:pass@host:5432/app?sslmode=require" --force
Expected Output
✓ Table 'orders' dropped successfully from PostgreSQL database
✓ All associated indexes and constraints removed

MongoDB

1# Drop collection from MongoDB
2akron drop-table users --db "mongodb://localhost:27017/myapp"
3
4# Drop with authentication
5akron drop-table events --db "mongodb://user:password@localhost:27017/analytics" --force
Expected Output
✓ Collection 'users' dropped successfully from MongoDB database
✓ All documents and indexes removed

Safety Features

Confirmation Prompt

By default, the command asks for confirmation before dropping tables:

1akron drop-table important_data --db "sqlite:///app.db"
2Are you sure you want to drop table 'important_data'? (y/N):

Backup Recommendation

Always backup your data before dropping tables:

1# Backup before dropping (example for SQLite)
2cp myapp.db myapp_backup.db
3
4# Then safely drop table
5akron drop-table old_table --db "sqlite:///myapp.db"

Error Handling

Common Errors

  • Table does not exist: Verify table name with inspect-schema
  • Permission denied: Ensure database user has DROP privileges
  • Foreign key constraints: Drop dependent tables first
  • Connection failed: Verify database URL and credentials

Troubleshooting

1# Check if table exists
2akron inspect-schema --db "sqlite:///myapp.db"
3
4# List all tables
5akron inspect-schema --db "mysql://user:pass@host:3306/db" --tables-only
6
7# Check for foreign key constraints (PostgreSQL/MySQL)
8# Drop dependent tables first, then the main table

Related Commands