1

I'm creating migration in Laravel and when I run command php artisan migrate the command give me the following error

Duplicate column name 'user_id' ('id' int unsigned not null auto_increment primary key, 'user_id' int unsigned not null, 'user_id' int not null, 'order_id_' int unsigned not null, 'order_id' int not null) default character set utf8 collate utf8_unicode_ci)

This is my migration:

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUserOrrderTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
         Schema::create('user_orrder', function (Blueprint $table) {

            $table->increments('id');

            $table->integer('user_id')->unsigned();
            $table->integer('user_id')->references('id')->on('users');

            $table->integer('order_id')->unsigned();
            $table->integer('order_id')->references('id')->on('orders');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('user_orrder');
    }
}

1 Answer 1

2

Your code should be as:

$table->foreign('user_id')->references('id')->on('users');

instead of $table->integer('user_id')->references('id')->on('users');

Read the docs.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.