Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alcir-junior-caju/e84869e4c40b0598b867acbe819d5be1 to your computer and use it in GitHub Desktop.
Save alcir-junior-caju/e84869e4c40b0598b867acbe819d5be1 to your computer and use it in GitHub Desktop.
Error Migrations
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateCouponsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('coupons', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('title');
$table->string('slug')
->unique();
$table->enum('status', ['ACTIVE', 'INACTIVE'])
->default('ACTIVE');
$table->string('school')
->nullable();
$table->string('description')
->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('coupons');
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateCodesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('codes', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('title');
$table->string('slug')
->unique();
$table->enum('status', ['ACTIVE', 'INACTIVE'])
->default('ACTIVE');
$table->date('expired_date');
$table->char('code', 12);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('codes');
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddCouponIdUserIdToCodesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('codes', function (Blueprint $table) {
$table->unsignedBigInteger('coupon_id');
$table->foreign('coupon_id')
->references('id')
->on('coupons')
->onUpdate('cascade')
->onDelete('set null');
$table->unsignedBigInteger('user_id');
$table->foreign('user_id')
->references('id')
->on('users')
->onUpdate('cascade')
->onDelete('set null');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('codes', function (Blueprint $table) {
$table->dropForeign('users_user_id_foreign');
$table->dropColumn('user_id');
$table->dropForeign('coupons_coupon_id_foreign');
$table->dropColumn('coupon_id');
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment