Laravel migration: “Foreign key constraint is incorrectly formed” (errno 150)

后端 未结 22 942
有刺的猬
有刺的猬 2020-11-30 07:21

When migrating my DB, this error appears. Below is my code followed by the error that I am getting when trying to run the migration.

Code



        
22条回答
  •  北荒
    北荒 (楼主)
    2020-11-30 07:59

    Migrations must be created top-down.

    First create the migrations for the tables who don't belong to anyone.

    Then create the migrations for tables that belong to the previous.


    Simplified answer to the table engine problem:

    To set the storage engine for a table, set the engine property on the schema builder:

    Schema::create('users', function ($table) {
        $table->engine = 'InnoDB';
    
        $table->increments('id');
    });
    

    From Laravel Docs: https://laravel.com/docs/5.2/migrations

提交回复
热议问题