Loading...
Loading...
Laravel 12 database migrations - Schema Builder, columns, indexes, foreign keys, seeders. Use when designing database schema or managing migrations.
npx skill4agent add fusengine/agents laravel-migrationsTeamCreate| Feature | Description |
|---|---|
| Schema Builder | Create, modify, drop tables |
| Columns | 50+ column types with modifiers |
| Indexes | Primary, unique, fulltext, spatial |
| Foreign Keys | Constraints with cascade options |
| Seeders | Populate tables with data |
Need schema change?
├── New table → make:migration create_X_table
├── Add column → make:migration add_X_to_Y_table
├── Modify column → make:migration modify_X_in_Y_table
├── Add index → make:migration add_index_to_Y_table
└── Seed data → make:seeder XSeeder| Use Case | Type | Example |
|---|---|---|
| Primary Key | | Auto-increment BIGINT |
| Foreign Key | | References parent |
| UUID Primary | | UUIDs |
| Boolean | | is_active |
| Enum | | order_status |
| JSON | | preferences |
| Money | | 99999999.99 |
| Timestamps | | created_at, updated_at |
| Soft Delete | | deleted_at |
| Scenario | onDelete | Use Case |
|---|---|---|
| Strict integrity | | Financial records |
| Auto-cleanup | | Post → Comments |
| Preserve with null | | Optional relations |
| No action | | Audit logs |
| Topic | Reference | When to Consult |
|---|---|---|
| Schema | schema.md | Table operations |
| Columns | columns.md | Column types |
| Indexes | indexes.md | Performance indexes |
| Foreign Keys | foreign-keys.md | Constraints |
| Commands | commands.md | Artisan commands |
| Seeding | seeding.md | Populate data |
| Topic | Reference | When to Consult |
|---|---|---|
| Testing | testing.md | Test migrations |
| Production | production.md | Deploy safely |
| Troubleshooting | troubleshooting.md | Fix errors |
| Template | When to Use |
|---|---|
| CreateTableMigration.php.md | New table |
| ModifyTableMigration.php.md | Alter table |
| PivotTableMigration.php.md | Many-to-many |
| Seeder.php.md | Seed patterns |
| MigrationTest.php.md | Test migrations |
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->string('title');
$table->text('content');
$table->enum('status', ['draft', 'published'])->default('draft');
$table->timestamps();
$table->softDeletes();
$table->index(['user_id', 'status']);
});Schema::table('posts', function (Blueprint $table) {
$table->string('slug')->after('title')->unique();
$table->boolean('featured')->default(false);
});php artisan make:migration create_posts_table
php artisan migrate
php artisan migrate:rollback --step=1
php artisan migrate:fresh --seedforeignId()->constrained()--pretend