Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Add a new column to existing table in a migration

I can't figure out how to add a new column to my existing database table using the Laravel framework.

I tried to edit the migration file using...
<?php

public function up()
{
Schema::create('users', function ($table) {
$table->integer("paid");
});
}


In terminal, I execute php artisan migrate:install and migrate.

How do I add new columns?
by

2 Answers

Bharatgxwzm
If you're using Laravel 5, the command would be;
php artisan make:migration add_paid_to_users


All of the commands for making things (controllers, models, migrations etc) have been moved under the make: command.

php artisan migrate is still the same though.
pankajshivnani123
You can add new columns within the initial Schema::create method like this:

Schema::create('users', function($table) {
$table->integer("paied");
$table->string("title");
$table->text("description");
$table->timestamps();
});

If you have already created a table you can add additional columns to that table by creating a new migration and using the Schema::table method:

Schema::table('users', function($table) {
$table->string("title");
$table->text("description");
$table->timestamps();
});

The documentation is fairly thorough about this, and hasn't changed too much from version 3 to version 4.

Login / Signup to Answer the Question.