Insert data into Oracle table "no returning id into"?

Asked

Viewed 150 times

1

I’m using Laravel 5.2 and when I have enter data he wants to return the last, but at the moment I want to enter and know if the operation was successful. My role in the controller is like this:

public function cadastrar(),
{
        $codigo= Request::input('codigo');
        $codigo1 = Request::input('codigo1');

        $model= new ModelCriado();
        $model->CD_SEQUENCIA   = "SEQUENCIA.NEXTVAL";
        $model->CD_CODIGO      = $codigo;
        $model->CD_CODIGO1     = $codigo1;
        $model->save();
        return response()->json( array( "response" => 1 ) );
    }

but he’s giving that message:

Error Code: 904 Error Message : ORA-00904: "ID": invalid Identifier Position : 128 Statement : Insert into model (CD_SEQUENCIA, CD_CODIGO, CD_CODIGO1) values (:P0, :P1, :P2) returning id into :P3 Bindings : [SEQ_MODEL.NEXTVAL,759,123,0]

my table only has 3 columns

CD_SEQUENCIA, CD_CODIGO, CD_CODIGO1

How do I fix it?

EDITION 1

class ModelCriado extends Model
{
    protected $table = "model_criado";
    public $timestamps = false; 
}
  • Post your model?!

  • Already. I edited to show my model

  • Sorry but this table has some serial field, auto or you pass the 3 values.?

  • I call a sequence

  • then let’s understand, the field CD_SEQUENCIA is your Sequencia or the bank will generate this value?

  • Exactly. That’s right!

  • I made an answer, but I don’t know the correct behavior to ORACLE and maybe all this depends on how the package is configured, the important thing that you inform this package on the question too, so that we can see the possibilities, I know that Eloquent for SQLSERVER, Mysql and Posgres works perfectly now ORACLE has not had any experience.

  • I found your answer modest, rsrs, because it solved my problem, but that it could work 100% I had to create a Rigger in the oracle that did the auto increment similar to mysql, the one without calling the field. Thanks for the help

  • So the package is like this, it’s not my fault kkkkk understood!

Show 4 more comments

1 answer

1


Good by the looks of your bank the field CD_SEQUENCIA is the field that has its value generated by the data bank, so try to configure the Model, informing their $primaryKey:

class ModelCriado extends Model
{
    protected $table = "model_criado";
    public $timestamps = false;    
    protected $primaryKey = 'CD_SEQUENCIA';
    protected $fillable = ['CD_CODIGO', 'CD_CODIGO1'];
}

and try to enter with the code below:

public function cadastrar()
{
    $codigo= Request::input('codigo');
    $codigo1 = Request::input('codigo1');

    $model= new ModelCriado();  
    $model->CD_CODIGO = $codigo;
    $model->CD_CODIGO1 = $codigo1;
    $model->save();
    return response()
          ->json( array( "response" => 1 ) );
}

public function cadastrar()
{
    $codigo= Request::input('codigo');
    $codigo1 = Request::input('codigo1');

    $model= new ModelCriado();  
    $model->CD_CODIGO = $codigo;
    $model->CD_CODIGO1 = $codigo1;
    $model->save();
    return response()
          ->json( array( "response" => 1 ) );
}

or

public function cadastrar()
{
    $codigo= Request::input('codigo');
    $codigo1 = Request::input('codigo1');

    $model = ModelCriado::create(Request::all());   

    return response()
          ->json( array( "response" => 1 ) );
}

or

public function cadastrar()
{
    $codigo= Request::input('codigo');
    $codigo1 = Request::input('codigo1');

    $model = new ModelCriado(Request::all());   
    $model->save();

    return response()
          ->json( array( "response" => 1 ) );
}

or

public function cadastrar()
{
    $codigo= Request::input('codigo');
    $codigo1 = Request::input('codigo1');

    $model = new ModelCriado();
    $model->fill(Request::all());
    $model->save();

    return response()
          ->json( array( "response" => 1 ) );
}
  • What does the variable $fillable mean?

  • @adventist I did not complete the answer, but, $fillable means mass recording, and a way to register I’ll edit and put in the answer

  • Only with create is it possible to save too?

  • there’s another way you can see too

  • Sure, it’s just that they’re my first steps with Laravel

  • Not being able to recover this last record, but is for next question rsrs. And researches also

  • @adventistaam check if you are after the save code, type $model->save(); var_dump($save->toArray()); just to check if you have returned.

  • Variable $save even?

  • No apology $model->toArray() !!!

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.