wheels dbmigrate create column
Generate a migration file for adding columns to an existing database table.
Synopsis
Alias: wheels db create column
Description
The dbmigrate create column
command generates a migration file that adds a column to an existing database table. It supports standard column types and various options for column configuration.
Parameters
name
string
Yes
-
The name of the database table to modify
data-type
string
Yes
-
The column type to add
column-name
string
No
-
The column name to add
default
any
No
-
The default value to set for the column
--null
boolean
No
true
Should the column allow nulls
limit
number
No
-
The character limit of the column
precision
number
No
-
The precision of the numeric column
scale
number
No
-
The scale of the numeric column
Column Types
string
- VARCHAR(255)text
- TEXT/CLOBinteger
- INTEGERbiginteger
- BIGINTfloat
- FLOATdecimal
- DECIMALboolean
- BOOLEAN/BITdate
- DATEtime
- TIMEdatetime
- DATETIME/TIMESTAMPtimestamp
- TIMESTAMPbinary
- BLOB/BINARY
Migration File Naming
The generated migration file will be named with a timestamp and description:
Example:
Examples
Add a simple column
Add column with default value
Add nullable column with limit
Add decimal column with precision
Generated Migration Example
For the command:
Generates:
Use Cases
Adding User Preferences
Add preference column to user table:
Adding Audit Fields
Add tracking column to any table:
Adding Price Fields
Add decimal columns for pricing:
Best Practices
1. Consider NULL Values
For existing tables with data, make new columns nullable or provide defaults:
2. Use Appropriate Types
Choose the right column type for your data:
3. One Column Per Migration
This command creates one column at a time:
4. Plan Your Schema
Think through column requirements before creating:
Data type and size
Null constraints
Default values
Index requirements
Advanced Scenarios
Adding Foreign Keys
Add foreign key columns with appropriate types:
Complex Column Types
For special column types, use blank migrations:
Common Pitfalls
1. Non-Nullable Without Default
2. Changing Column Types
This command adds columns, not modifies them:
Notes
The migration includes automatic rollback with removeColumn()
Column order in down() is reversed for proper rollback
Always test migrations with data in development
Consider the impact on existing queries and code
Related Commands
wheels dbmigrate create table
- Create new tableswheels dbmigrate create blank
- Create custom migrationswheels dbmigrate remove table
- Remove tableswheels dbmigrate up
- Run migrationswheels dbmigrate down
- Rollback migrations
Last updated
Was this helpful?