I'm trying to create foreign keys in Laravel 5.7 however when I migrate my table using artisan i am thrown the following error:
Illuminate\Database\QueryException:
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table
gateway_transactionsadd constraintgateway_transactions_user_id_foreignforeign key (user_id) referencesusers(id) on delete CASCADE)
my migration :
public function up()
{
Schema::create('gateway_transactions', function (Blueprint $table) {
$table->engine = "innoDB";
$table->unsignedBigInteger('id', true);
$table->integer('user_id')->unsigned();
$table->enum('provider', \Parsisolution\Gateway\GatewayManager::availableDrivers());
$table->decimal('amount', 15, 2);
$table->integer('order_id')->nullable();
$table->string('currency', 3)->nullable();
$table->string('ref_id', 100)->nullable();
$table->string('tracking_code', 50)->nullable();
$table->string('card_number', 50)->nullable();
$table->enum('status', \Parsisolution\Gateway\Transaction::availableStates())
->default(\Parsisolution\Gateway\Transaction::STATE_INIT);
$table->string('ip', 20)->nullable();
$table->json('extra')->nullable();
$table->timestamp('paid_at')->nullable();
$table->nullableTimestamps();
$table->softDeletes();
});
Schema::table('gateway_transactions', function(Blueprint $table) {
$table->foreign('user_id')->references('id')->on('users')->onDelete('CASCADE');
});
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire