You must create your migration in order, for example, I want my users have a role_id field that is in my roles table
I will start my migration of php artisan make:migration create_roles_table --create=roles role first php artisan make:migration create_roles_table --create=roles
then my second user migration php artisan make:migration create_users_table --create=users
php artisan migration will be executed using the order of the generated files 2017_08_22_074128 _create_roles_table.php and 2017_08_22_134306 _create_users_table to check the datetime order, which will be the order of execution.
files 2017_08_22_074128_create_roles_table.php
public function up() { Schema::create('roles', function (Blueprint $table) { $table->increments('id'); $table->string('name', 50); $table->timestamps(); }); }
2017_08_22_134306_create_users_table
public function up() { Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->integer('role_id')->unsigned(); $table->string('name'); $table->string('phone', 20)->unique(); $table->string('password'); $table->rememberToken(); $table->boolean('active'); $table->timestamps(); $table->foreign('role_id')->references('id')->on('roles'); }); }
Napster scofield
source share