SQLSTATE[HY000]: General error: 1005 Can't create table project
.#sql-4b4_46
(errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table projects
add constraint projects_owner_id_foreign
foreign key (owner_id
) references users
(id
) on delete cascade)
Schema::create('projects', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedInteger('owner_id');
$table->string('title');
$table->text('description');
$table->timestamps();
$table->foreign('owner_id')->references('id')->on('users')->onDelete('cascade');
});
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
projects
andusers
tables. Try creating theusers
table before defining schema create forprojects
. Also, theprojects.owner_id
could be bigInteger type to match the bigIncrements forusers.id
. – Igor