Bird
0
0

Which of the following is the correct syntax to add an auto-incrementing primary key column named 'id' in a Laravel migration?

easy📝 Syntax Q3 of 15
Laravel - Database Basics and Migrations
Which of the following is the correct syntax to add an auto-incrementing primary key column named 'id' in a Laravel migration?
A$table->primary('id');
B$table->increments('id');
C$table->integer('id')->autoIncrement();
D$table->bigInteger('id')->primary();
Step-by-Step Solution
Solution:
  1. Step 1: Recall the Laravel method for auto-increment primary key

    The method increments creates an auto-incrementing integer primary key.
  2. Step 2: Verify the syntax correctness

    $table->increments('id'); is the standard and correct syntax.
  3. Final Answer:

    $table->increments('id'); -> Option B
  4. Quick Check:

    Auto-increment primary key = $table->increments() [OK]
Quick Trick: Use $table->increments('id') for auto-increment keys [OK]
Common Mistakes:
  • Using $table->integer() without autoIncrement()
  • Using $table->primary() alone without increments
  • Using bigInteger without increments for id

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes