Create database tables with schema definitions, foreign key relationships, and cross-database compatibility.
The create_table()
method creates database tables with type-safe schema definitions. It uses CREATE TABLE IF NOT EXISTS
to prevent errors on duplicate creation and supports foreign key relationships across all supported databases.
create_table(table_name: str, schema: Dict[str, str]) -> None
Type: str
Name of the table to create. Must be a valid identifier for the target database.
Type: Dict[str, str]
Dictionary mapping column names to their types. Supported types:
"int"
- Integer (becomes PRIMARY KEY AUTOINCREMENT for id columns)"str"
- String/VARCHAR"float"
- Floating point number"bool"
- Boolean"int->table.column"
- Foreign key referenceNone - The method performs the table creation and returns nothing.
Users table created successfully!
Generated SQL (SQLite):
Use the syntax "int->table.column"
to create foreign key relationships:
Blog schema created with foreign key relationships!
Complex schema with multiple relationships:
E-commerce database schema created!
Types are mapped to SQLite's flexible type system:
int
โ INTEGER (PRIMARY KEY AUTOINCREMENT for id columns)str
โ TEXTfloat
โ REALbool
โ BOOLEANTypes are mapped to MySQL's strict type system:
int
โ INT AUTO_INCREMENT PRIMARY KEYstr
โ VARCHAR(255)float
โ FLOATbool
โ BOOLEANTypes use PostgreSQL's robust type system:
int
โ SERIAL PRIMARY KEYstr
โ VARCHAR(255)float
โ REALbool
โ BOOLEANMongoDB collections are created implicitly. Schema definitions are stored for reference but not enforced:
Table creation failed: Foreign key constraint failed: categories Table product_reviews created successfully!
You can also create tables using the Akron CLI:
Table users created. Table posts created. Table products created.
"int->table_name.column_name"
"int->users.id"
IF NOT EXISTS
behavior for safe re-runsAfter creating tables, you can start working with data: