Run command berikut
php artisan make:migration tukar_field_type_table_parcel
Edit file migration TukarFieldTypeTableParcel.php seperti berikut
Function Up()
public function up()
{
//
Schema::table('parcels', function(Blueprint $table)
{
$table->integer('courier')->unsigned()->change();
$table->foreign('courier')->references('id')->on('couriers');
$table->integer('distributor')->unsigned()->change();
$table->foreign('distributor')->references('id')->on('distributors');
});
}
Function Down()
public function down()
{
//
Schema::table('parcels', function(Blueprint $table)
{
$table->dropForeign('parcels_courier_foreign');
$table->dropForeign('parcels_distributor_foreign');
});
}
*Unsigned() – Bertujuan memastikan nilai integer berkenaan bukan negative
*Sila pastikan type untuk setiap foreginer field dan reference field adalah sama.
Leave a Reply