Bird
0
0

Which migration snippet correctly adds a nullable profile_picture string column to the existing users table?

hard📝 Application Q8 of 15
Laravel - Database Basics and Migrations
Which migration snippet correctly adds a nullable profile_picture string column to the existing users table?
ASchema::create('users', function (Blueprint $table) { $table->string('profile_picture')->nullable(); });
BSchema::table('users', function (Blueprint $table) { $table->string('profile_picture')->nullable(); });
CSchema::table('users', function (Blueprint $table) { $table->string('profile_picture'); });
DSchema::table('users', function (Blueprint $table) { $table->text('profile_picture')->nullable(); });
Step-by-Step Solution
Solution:
  1. Step 1: Use Schema::table to modify existing table

    Adding columns requires modifying the existing table, not creating it.
  2. Step 2: Define the column as string and nullable

    The column should be a string and allow null values.
  3. Step 3: Review options

    Schema::table('users', function (Blueprint $table) { $table->string('profile_picture')->nullable(); }); correctly uses Schema::table and nullable() on a string column.
  4. Final Answer:

    Schema::table('users', function (Blueprint $table) { $table->string('profile_picture')->nullable(); }); -> Option B
  5. Quick Check:

    Use Schema::table and nullable() for optional columns [OK]
Quick Trick: Use Schema::table and nullable() for optional columns [OK]
Common Mistakes:
  • Using Schema::create instead of Schema::table
  • Omitting nullable() for optional columns
  • Using text instead of string for short strings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes