Laravel迁移:在引用它之前创建引用的表

Here is my migration method:

public function up()
{
    Schema::create('items', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->integer('item_type_id')->unsigned();
        $table->integer('character_class');
        $table->integer('character_race');
        $table->integer('required_level');
        $table->integer('quality');
        $table->integer('durability');
        $table->integer('buy_price');
        $table->integer('sell_price');
        $table->timestamps();
    });

    Schema::table('items', function($table) {
        $table->foreign('item_type_id')->references('id')->on('item_types')->onDelete('cascade');
    });
}

The problem is that migration for the item_types table is after items migration. So there is no item_types table while creating items table, then migration will fail at creating foreign key. Is there a way to delay foreign constraints and run them after table creations? Or I have to separate the foreign constraints to another migration?! Thanks.

There are two solutions:

1

Create item_types table before this migration (which is natural situation).

2

If the above is imposible for some reason then you have to move this:

Schema::table('items', function($table) {
        $table->foreign('item_type_id')->references('id')->on('item_types')->onDelete('cascade');
    });

To the end of up method in item_types table migration.