To create a migration, you may use the migrate:make command on the Artisan CLI. Use a specific name to avoid clashing with existing models.
php artisan make:migration add_newcolumn_to_users_table --table=users
You then need to use the Schema::table()
method (as you’re accessing an existing table, not creating a new one). And you can add a column like this:
public function up()
{
Schema::table('users', function($table) {
$table->integer('newcolumn');
});
}
and don’t forget to add the rollback option:
public function down()
{
Schema::table('users', function($table) {
$table->dropColumn('newcolumn');
});
}
Then you can run your migrations:
php artisan migrate
This is all well covered in the documentation for both Laravel 3: