wheels dbmigrate create table
Generate a migration file for creating a new database table.
Synopsis
Description
The dbmigrate create table
command generates a migration file that creates a new database table with specified columns. It automatically includes timestamp columns (createdAt, updatedAt) and provides a complete table structure following CFWheels conventions.
Arguments
<table_name>
<table_name>
Type: String
Required: Yes
Description: The name of the table to create (singular form recommended)
[columns...]
[columns...]
Type: String (multiple)
Required: No
Format:
name:type:options
Description: Column definitions in the format name:type:options
Options
--id
--id
Type: String
Default:
id
Description: Name of the primary key column (use --no-id to skip)
--no-id
--no-id
Type: Boolean
Default:
false
Description: Skip creating a primary key column
--timestamps
--timestamps
Type: Boolean
Default:
true
Description: Include createdAt and updatedAt columns
--no-timestamps
--no-timestamps
Type: Boolean
Default:
false
Description: Skip creating timestamp columns
--datasource
--datasource
Type: String
Default: Application default
Description: Target datasource for the migration
--force
--force
Type: Boolean
Default:
false
Description: Overwrite existing migration file
Column Types
Supported column types:
string
- VARCHAR(255)text
- TEXT/CLOBinteger
- INTEGERbiginteger
- BIGINTfloat
- FLOATdecimal
- DECIMALboolean
- BOOLEAN/BITdate
- DATEtime
- TIMEdatetime
- DATETIME/TIMESTAMPtimestamp
- TIMESTAMPbinary
- BLOB/BINARY
Column Options
Column options are specified after the type with colons:
:null
- Allow NULL values:default=value
- Set default value:limit=n
- Set column length/size:precision=n
- Set decimal precision:scale=n
- Set decimal scale
Examples
Create a basic table
Create table with columns
Create table with column options
Create table without timestamps
Create join table without primary key
Generated Migration Example
For the command:
Generates:
Use Cases
Standard Entity Table
Create a typical entity table:
Join Table for Many-to-Many
Create a join table for relationships:
Configuration Table
Create a settings/configuration table:
Audit Log Table
Create an audit trail table:
Best Practices
1. Use Singular Table Names
CFWheels conventions expect singular table names:
2. Include Foreign Keys
Add foreign key columns for relationships:
3. Set Appropriate Defaults
Provide sensible defaults where applicable:
4. Consider Indexes
Plan for indexes (add them in separate migrations):
Advanced Options
Custom Primary Key
Specify a custom primary key name:
Composite Keys
For composite primary keys, use blank migration:
Notes
Table names should follow your database naming conventions
The migration automatically handles rollback with dropTable()
Column order in the command is preserved in the migration
Use
wheels dbmigrate up
to run the generated migration
Related Commands
Last updated
Was this helpful?