Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

asteriks's avatar

ORA-00957: duplicate column name

Hello All.

I'm having this console output

Illuminate\Database\QueryException

Error Code : 957 Error Message : ORA-00957: duplicate column name Position : 239 Statement : create table user_authentication ( id number(19,0) not null, autenticacion_tipo_id number(19,0) not null, nivel_auth varchar2(255) not null, fecha_autenticacion timestamp not null, updated_at timestamp not null, created_at timestamp null, updated_at timestamp null, constraint user_authentication_id_fk foreign key ( id ) references users ( id ) on delete cascade, constraint us_authentic_autentic_ti_id_fk foreign key ( autenticacion_tipo_id ) references authentication_types ( id ) on delete cascade, constraint user_authentication_id_pk primary key ( id ) ) Bindings : [] (SQL: create table user_authentication ( id number(19,0) not null, autenticacion_tipo_id number(19,0) not null, nivel_auth varchar2(255) not null, fecha_autenticacion timestamp not null, updated_at timestamp not null, created_at timestamp null, updated_at timestamp null, constraint user_authentication_id_fk foreign key ( id ) references users ( id ) on delete cascade, constraint us_authentic_autentic_ti_id_fk foreign key ( autenticacion_tipo_id ) references authentication_types ( id ) on delete cascade, constraint user_authentication_id_pk primary key ( id ) ))

This is the user migration:

 $a = Schema::create('users', function (Blueprint $table) {
            $table->id()->primary();
            $table->bigInteger('cuil')->unique();
            $table->bigInteger('prs_id')->unique();
            $table->string('email');
            $table->string('password');
            $table->string('nombre');
            $table->string('apellido');

            $table->timestamp('email_verified_at')->nullable();

            $table->rememberToken();
            $table->timestamps();
        });

user_contact migrations:

Schema::create('user_contact', function (Blueprint $table) {
    $table->id()->primary();
    $table->foreign('id')->references('id')->on('users')->onDelete('cascade');
    $table->string("email")->unique(); 
    $table->string("fecha_nacimiento"); 
    $table->string("celular"); 
    $table->string("departamento_id"); 
    $table->string("localidad_id"); 
    $table->string("domicilio"); 
    $table->string("numero");
    $table->timestamps();
    $table->softDeletes();
});

and this is the user_authentication tables which has the problem

 Schema::create('user_authentication', function (Blueprint $table) {

            $table->id()->primary();
            $table->foreign('id')->references('id')->on('users')->onDelete('cascade');

            $table->bigInteger("autenticacion_tipo_id");
            $table->foreign('autenticacion_tipo_id')->references('id')->on('authentication_types')->onDelete('cascade');

            $table->string("nivel_auth"); 
            $table->timestamp("fecha_autenticacion");
            $table->timestamp("updated_at");

            $table->timestamps();
        });

I can't find where it is duplicated.

Could it be the problem that more than one table has this line?

  $table->foreign('id')->references('id')->on('users')->onDelete('cascade');
0 likes
9 replies
vincent15000's avatar

You are trying to create 2 fields with the same name.

// $table->bigInteger("autenticacion_tipo_id");
$table->foreign('autenticacion_tipo_id')->references('id')->on('authentication_types')->onDelete('cascade');

foreign already creates the field, so you don't need bigInteger.

1 like
asteriks's avatar

@vincent15000

thanks, but what happens when i define a foreign key with the id? As it is in the following way. It is not defined 2 times in that case?

        $table->id()->primary();
        $table->foreign('id')->references('id')->on('users')->onDelete('cascade');
1 like
vincent15000's avatar

@asteriks What version of Laravel are you using ?

And what is the error message ? Which column is attempted to be created twice ?

I think that I am confused between foreign and foreignId. So what I said to you is false, foreign effectively defines an existing field as a foreign key whereas foreignId creates a new field and defines it as a foreign key.

1 like
asteriks's avatar

@vincent15000

Laravel 9.

Could it be that there is more than one table that has this statement?

 $table->foreign('id')->references('id')->on('users')->onDelete('cascade');
1 like
vincent15000's avatar

@asteriks Either you write this.

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

Or you write that.

$table->foreignId('user_id')->constrained()->onDelete('cascade');
vincent15000's avatar

@asteriks Have you checked if you don't already have the table created while running the migration ?

For me, in some cases, when I run a migration that fails, there are cases where the table is created anyway, but the migration is not registered. So I have to delete the table manually before re-running the migration.

Tray2's avatar

@asteriks You are trying to create multiple columns with the same name.

I suggest you read that post again and follow the recommendations on how to write in your migrations file.

Or use this syntax instead

    public function up(): void
    {
        Schema::create('records', function (Blueprint $table) {
            $table->id();
            $table->string('title');
            $table->integer('release_year');
            $table->string('barcode');
            $table->string('spine_code');
            $table->foreignIdFor(Artist::class);
            $table->foreignIdFor(Genre::class);
            $table->foreignIdFor(Format::class);
            $table->foreignIdFor(RecordLabel::class);
            $table->foreignIdFor(Country::class);
            $table->timestamps();
        });
    }

https://github.com/Tray2/mediabase/blob/main/database/migrations/2022_09_30_222550_create_records_table.php

Please or to participate in this conversation.