Migrations: When to use index()?

Posted 8 months ago by DoeJohn

Should I addindex() for every field? Or just use it on foreign keys? Or?

For example, here's one migration:

    public function up()
        Schema::create('posts', function (Blueprint $table) {





            $table->unique(['category_id', 'slug']);

Which fields in this migration should be indexed? For example, I always add them on foreign keys:


Is this wrong (to always use index() on foreign keys)?

Would you index some other fields in this migration? If yes, which one?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.