Add a new column to existing table in a migration
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
for Laravel 3:
php artisan migrate:make add_paid_to_users
for Laravel 5+:
php artisan make:migration add_paid_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('user_master_transational', function (Blueprint $table) {
$table->string('vFirstName', 25)->collation('utf8mb4_unicode_ci')->nullable()
->after('iUserId');
$table->string('vLastName', 25)->collation('utf8mb4_unicode_ci')->nullable()
->after('iUserId');
});
}
and don't forget to add the rollback option:
public function down()
{
Schema::table('users', function($table) {
$table->dropColumn('paid');
});
}
Then you can run your migrations:
php artisan migrate
Single migration RUN
php artisan migrate --path=/database/migrations/2020_06_25_105657_table.php