Version control for your database schema
Method | SQL Type | Description | Example |
---|---|---|---|
increments(name) | INTEGER AUTO_INCREMENT | Auto-incrementing primary key | table.increments('id') |
bigIncrements(name) | BIGINT AUTO_INCREMENT | Large auto-incrementing key | table.bigIncrements('id') |
uuid(name) | CHAR(36) | UUID column | table.uuid('id').primary() |
Method | SQL Type | Description | Example |
---|---|---|---|
string(name, length) | VARCHAR | Text with max length (default 255) | table.string('name', 100) |
text(name) | TEXT | Long text (up to 65,535 chars) | table.text('description') |
mediumText(name) | MEDIUMTEXT | Medium text (up to 16MB) | table.mediumText('content') |
longText(name) | LONGTEXT | Very long text (up to 4GB) | table.longText('article') |
char(name, length) | CHAR | Fixed-length string | table.char('country_code', 2) |
Method | SQL Type | Description | Example |
---|---|---|---|
integer(name) | INTEGER | 32-bit integers (-2B to 2B) | table.integer('age') |
bigInteger(name) | BIGINT | 64-bit integers | table.bigInteger('views') |
smallInteger(name) | SMALLINT | 16-bit integers (-32K to 32K) | table.smallInteger('priority') |
tinyInteger(name) | TINYINT | 8-bit integers (-128 to 127) | table.tinyInteger('status') |
decimal(name, precision, scale) | DECIMAL | Exact decimal numbers | table.decimal('price', 8, 2) |
float(name, precision, scale) | FLOAT | Floating point numbers | table.float('rating', 3, 2) |
double(name) | DOUBLE | Double precision floats | table.double('coordinates') |
Method | SQL Type | Description | Example |
---|---|---|---|
date(name) | DATE | Date only (YYYY-MM-DD) | table.date('birth_date') |
datetime(name) | DATETIME | Date and time | table.datetime('created_at') |
timestamp(name) | TIMESTAMP | Unix timestamp | table.timestamp('updated_at') |
time(name) | TIME | Time only (HH:MM:SS) | table.time('start_time') |
year(name) | YEAR | Year only (1901-2155) | table.year('graduation_year') |
Method | SQL Type | Description | Example |
---|---|---|---|
boolean(name) | BOOLEAN/TINYINT | True/false values | table.boolean('is_active') |
json(name) | JSON | JSON data | table.json('metadata') |
jsonb(name) | JSONB | Binary JSON (PostgreSQL) | table.jsonb('settings') |
binary(name) | BLOB | Binary data | table.binary('file_data') |
enum(name, values) | ENUM | Predefined values | table.enum('status', ['active', 'inactive']) |
geometry(name) | GEOMETRY | Spatial data | table.geometry('location') |
point(name) | POINT | Geographic point | table.point('coordinates') |
Modifier | Description | Example |
---|---|---|
.notNullable() | Column cannot be null | table.string('name').notNullable() |
.nullable() | Column can be null (default) | table.string('bio').nullable() |
.defaultTo(value) | Set default value | table.boolean('active').defaultTo(true) |
.unique() | Column values must be unique | table.string('email').unique() |
.primary() | Set as primary key | table.uuid('id').primary() |
.unsigned() | Only positive numbers | table.integer('age').unsigned() |
.index() | Add database index | table.string('slug').index() |
.comment(text) | Add column comment | table.string('name').comment('Full name') |
.after(column) | Position after column (MySQL) | table.string('middle_name').after('first_name') |
.first() | Position as first column (MySQL) | table.string('id').first() |
Action | Description |
---|---|
CASCADE | Delete related records |
SET NULL | Set foreign key to null |
RESTRICT | Prevent deletion if related records exist |
NO ACTION | Do nothing (database default) |
Migration Already Exists
npx ilana migrate:status
npx ilana migrate:rollback
Foreign Key Constraint Error
Column Already Exists
schema.hasColumn()
npx ilana migrate:list