Laravel 7
Create a migration file using cli command:
php artisan make:migration add_paid_to_users_table --table=users
A file will be created in the migrations folder, open it in an editor.
Add to the function up():
Schema::table('users', function (Blueprint $table) {
// Create new column
// You probably want to make the new column nullable
$table->integer('paid')->nullable()->after('status');
}
Add to the function down(), this will run in case migration fails for some reasons:
$table->dropColumn('paid');
Run migration using cli command:
php artisan migrate
In case you want to add a column to the table to create a foreign key constraint:
In step 3 of the above process, you'll use the following code:
$table->bigInteger('address_id')->unsigned()->nullable()->after('tel_number');
$table->foreign('address_id')->references('id')->on('addresses')->onDelete('SET NULL');
In step 4 of the above process, you'll use the following code:
// 1. Drop foreign key constraints
$table->dropForeign(['address_id']);
// 2. Drop the column
$table->dropColumn('address_id');