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

julianov's avatar

ORA-01438 data type overflow

Hello everyone. I am using an oracle database, and when performing an insert, I get the following message:

"status": false, "message": "Error Code : 1438\nError Message : ORA-01438: value larger than specified precision allowed for this column\nPosition : 76\nStatement : insert into "USER_CONFIRMATION_CODES" ("ID", "CODE", "CREATED_AT") values (:p0, :p1, :p2) returning "ID" into :p3\nBindings : [23354412829,6284,2022-11-24 14:28:02,0]\n" }

Could you please help me where the problem is, because idx in user table is set as BigInteger.

this is the user table:

<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
              
            $table->id();
            $table->bigInteger('idx')->unique()->primary();
            $table->string('name');
            $table->string('last_name');
            $table->string('email');
            $table->string('password');

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

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

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

this is the user_confirmation_code:

<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user_confirmation_codes', function (Blueprint $table) {
            
            $table->increments('id');
            $table->foreign('id')->references('idx')->on('users')->onDelete('cascade');

            $table->integer('code');
            $table->timestamp('created_at')->nullable();

        });
    }

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

this is the controller method:

class UserController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
    }

    public function singup(Request $request)
    {

        try {
            $validated = $this->validate($request, [
                'idx' => 'required',
                'name' => 'required',
                'last_name' => 'required',
                'email' => 'required',
                'password' => 'required',
            ]);

            $user = new User();
            $user->idx= $validated['cuil'];
            $user->name= $validated['nombre'];
            $user->last_name = $validated['apellido'];
            $user->email = $validated['email'];

            $user->password = bcrypt($validated['password']);

            $user->save();

            $code = random_int(1000,9999);
            $validation_code = new UserConfirmationCode();
            $validation_code->id = $user->idx;
            $validation_code->code = $code;
            $validation_code->created_at = Carbon::now()->timestamp;
            $validation_code->save();

            Mail::to('[email protected]')
            ->cc('[email protected]')
            ->queue((new EmailConfirmation($user , $code))->from('[email protected]', 'Laravel'));

            return response()->json([
                'status' => true,
                'message' => 'Correo enviado',
            ], 201);

        } catch (\Throwable $th) {
            return response()->json([
                'status' => false,
                'message' => $th->getMessage()
            ], 500);
        }

    }

  
    public function destroy($id)
    {
        //
    }
}
0 likes
3 replies
Sinnbeck's avatar

Can you show the code that throws the error ?

1 like
julianov's avatar

@Sinnbeck Thanks, it looks like the problem is in the line

$validation_code->id = $user->idx;

But I don't know how to manage it because id from validation_code is a foreingkey.

Could it be that the foreign key is implemented incorrectly?

Tray2's avatar

@julianov The first value is the max value you can store in an integer in an oracle database, the second is what you are trying to store.

  • 2147483647
  • 23354412829
1 like

Please or to participate in this conversation.