Schema::create('projects', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->foreignId('project_id')->constrained();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
Schema::create('tasks', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained();
$table->string('name');
$table->timestamps();
});
When I run the php artisan migrate
only the users table gets created then the migration process stops...
SQLSTATE[HY000]: General error: 1005 Can't create table
Projectname
.users
(errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter tableusers
add constraintusers_project_id_foreign
foreign key (project_id
) referencesprojects
(id
))