Bird
0
0

Identify the error in this migration code:

medium📝 Debug Q14 of 15
Laravel - Database Basics and Migrations
Identify the error in this migration code:
public function up()
{
    Schema::create('comments', function (Blueprint $table) {
        $table->increments('id');
        $table->string('text');
        $table->timestamps;
    });
}
AString column 'text' must have a length specified
BUsing increments instead of id method
CTable name should be singular, not plural
DMissing parentheses after timestamps method call
Step-by-Step Solution
Solution:
  1. Step 1: Check method calls in migration

    $table->timestamps is missing parentheses. It should be $table->timestamps() to call the method.
  2. Step 2: Validate other parts

    Using increments('id') is valid, plural table names are allowed, and string columns default length is 255 if not specified.
  3. Final Answer:

    Missing parentheses after timestamps method call -> Option D
  4. Quick Check:

    Method calls need parentheses () [OK]
Quick Trick: Always add () when calling migration methods [OK]
Common Mistakes:
  • Forgetting parentheses on method calls
  • Thinking increments is invalid
  • Believing table names must be singular

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes