The issue is not with your migration. You're getting an error when trying to update a student model. Your id_provinsi column references the primary key on the users table. The foreign key constraint fails, so it looks like there's no user with ID 13.
public function up()
{
Schema::create('provinsi', function (Blueprint $table) {
$table->id();
$table->string('name')->default();
$table->timestamps();
});
}
public function up()
{
Schema::create('kota', function (Blueprint $table) {
$table->id();
$table->timestamps();
});
}
public function up()
{
Schema::create('kecamatan', function (Blueprint $table) {
$table->id();
$table->timestamps();
});
}
public function up()
{
Schema::create('kelurahan', function (Blueprint $table) {
$table->id();
$table->timestamps();
});
}
@Wizurai1302 If you're getting the exact same error, then you obviously haven't run the migrations.
Do you understand how migrations work? If you edit the migration file after running it, then running "php artisan migrate" won't do anything since the migration has already been handled. You need to either roll back the previous migration or use migrate:fresh which clears your DB and runs all migrations from scratch. If you're confused, I recommend you read Laravel's documentation on migrations.
The error message you provided indicates an integrity constraint violation in an SQL query. Specifically, it states that there is a foreign key constraint failure when trying to add or update a child row in the "students" table.
The foreign key constraint "students_id_provinsi_foreign" references the "id" column in the "users" table. The error suggests that the foreign key constraint is not being satisfied, meaning that the value being inserted or updated in the "id_provinsi" column of the "students" table does not exist in the referenced "id" column of the "users" table.
To resolve this issue, you need to ensure that the value being assigned to the "id_provinsi" column in the "students" table corresponds to an existing value in the "id" column of the "users" table. Double-check the data being used in the query and verify that the referenced foreign key values are correct and exist in the referenced table.