Skip to main content
Tutorial Free

Migrate "pretend" - view actual SQL queries before you run them

February 02, 2016
2 min read
Laravel has convenient database migrations mechanism, which allows us to track database changes and easily roll them back if needed. But what is hiding behind the scenes? What if we need to know actual SQL queries that have been generated during the migration? Or another scenario - what if we want to check the SQLs before they are actually run? There's a trick for both of it. Artisan command migrate comes with a neat option --pretend. All it does is generating SQLs and showing them for you in Terminal or Command line. Let's take a look at simple migration example:
class CreateTestTable extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('tests', function (Blueprint $table) {
            $table->increments('id');
            $table->string('title');
            $table->timestamps();
        });
    }
And now we run it with command php artisan migrate --pretend. Here's the result: 0202_laraveldaily_pretend_01 Not really pretty, but you can see the SQL statement here. And let's take it a step further and add another migration, really similar:
class CreateTest2Table extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('tests2', function (Blueprint $table) {
            $table->increments('id');
            $table->string('title2');
            $table->timestamps();
        });
    }
Same command - here's the result, it shows both commands one after another: 0202_laraveldaily_pretend_02 Simple, but useful trick. Do you know some more tricks with migrations? Let me know in the comments!

Enjoyed This Tutorial?

Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.

Recent Courses

Laravel Coding with AI Agents: Cursor, Claude Code, Codex

5 lessons
1 h 01 min

Laravel Modules and DDD

16 lessons
1 h 59 min

Laravel 12 For Beginners: Your First Project

15 lessons
1 h 32 min

Comments & Discussion

No comments yet…

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.