Bird
0
0

What will be the effect of running php artisan migrate with the following migration code?

medium📝 Predict Output Q4 of 15
Laravel - Database Basics and Migrations
What will be the effect of running php artisan migrate with the following migration code?
Schema::table('posts', function (Blueprint $table) {
    $table->text('description');
    $table->boolean('published')->default(false);
});
ARemoves 'description' and 'published' columns from 'posts' table
BCreates a new 'posts' table with 'description' and 'published' columns
CAdds a nullable text column 'description' and a boolean 'published' with default false to 'posts' table
DThrows an error because Schema::table cannot add columns
Step-by-Step Solution
Solution:
  1. Step 1: Understand Schema::table

    This modifies an existing table rather than creating a new one.
  2. Step 2: Adding columns

    The code adds a text column 'description' and a boolean 'published' with a default value of false.
  3. Final Answer:

    Adds a nullable text column 'description' and a boolean 'published' with default false to 'posts' table -> Option C
  4. Quick Check:

    Schema::table adds columns without errors [OK]
Quick Trick: Schema::table modifies existing tables [OK]
Common Mistakes:
  • Confusing Schema::table with Schema::create
  • Assuming columns are non-nullable by default
  • Believing default values are not set

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes