Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Laravel, can a migration file create more than one table?

I need to create a relevant amount of tables and checking the Laravel 4 documentation I see the following code:

Schema::create('users', function($table)
{
    $table->increments('id');
});

I assume that in one migration file, I can create as many tables as I want using the code above. Is this assumption right? Is it a bad practice?

like image 296
Italo André Avatar asked Jun 11 '13 15:06

Italo André


1 Answers

Yes, migrations can do multiple DB modifications (add tables, drop tables, add indexes, etc).

It is not considered bad form. A migration is a collection of steps necessary to upgrade/downgrade your database to the next/previous format, respectively

Schema::create('users', function($table)
{
    $table->increments('id');
});

Schema::create('rights', function($table)
{
    $table->increments('id');
});

In our case, migrations are tied to our ticket system. When a feature or bug is to be deployed, the appropriate migration is deployed with it. Sometimes we add columns, new tables, or drop stuff.

like image 114
Alexandre Danault Avatar answered Sep 20 '22 14:09

Alexandre Danault