, laravel-errno-150-foreign-key-constraint-is-incorrectly-formed , , laravel-errno-150-foreign-key-constraint-is-incorrectly-formed laravel.
1) : column name table name , , , .
2) : ->primary() ->unique() .
3) : . .
4) : , , , , migration table , php artisan migrate:reset , , .
5) : : , referenced , reference table , . , :
- A:
2014_10_12_000000_create_users_table.php - B:
2014_10_12_100000_create_password_resets_table.php
, A 2014_10_11_100000_create_password_resets_table.php B, , B 2014_10_11_100000_create_password_resets_table.php A.
6) Schema::enableForeignKeyConstraints(); : Schema::enableForeignKeyConstraints(); Schema::enableForeignKeyConstraints(); function up() :
class CreateUsersTable extends Migration
{
public function up()
{
Schema::enableForeignKeyConstraints();
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('users');
}
}
, laravel laravel.
, , .