New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Primary key not incrementing #155

Closed
gabrieloliverio opened this Issue Mar 11, 2016 · 8 comments

Comments

Projects
None yet
3 participants
@gabrieloliverio

gabrieloliverio commented Mar 11, 2016

Do you have any idea on why my primary key is not incrementing?

This is my model:

namespace App\Models;

use Yajra\Oci8\Eloquent\OracleEloquent as Model;

class Test extends Model
{
    public $timestamps = false;
    protected $table = "schema.TES_TEST";
    protected $primaryKey = 'TES_IDTEST';
    protected $sequence = 'SQ_TES_ID';
}

Here is how I try to insert:

public function store(Request $request)
    {
        $test = new Test();
        $test->TES_DCTEST = 'Test 1';
        $test->save();
    }

The error message is the following:

Error Message : ORA-01400: cannot insert NULL into  ("schema"."TES_TEST"."TES_IDTEST")
Position : 0
Statement : insert into schema.TES_TEST (TES_DCTEST) values (:p0) returning TES_IDTEST into :p1
Bindings : [Test 1,0]

I also tried using de DB facade and the same error is raised:

DB::connection('oracle')->table('schema.TES_TEST')->insertGetId(
    ['TES_DCTEST' => 'teste'], 'TES_IDTEST'
);

The table and sequence wasn't created using migrations, it was already created and it works properly in PL/SQL Developer.

Despite the inserts don't work, selects, updates and deletes work well.

@yajra

This comment has been minimized.

Owner

yajra commented Mar 12, 2016

@gabrieloliverio, setting a custom sequence is not yet fully functional. ATM, I think you need to set the id manually by getting the next value of the sequence. See https://github.com/yajra/laravel-oci8/wiki/Oracle-Sequence.

BTW, do you have your own auto-increment trigger on your table? Will dig this further when I got the chance. Thanks!

@gabrieloliverio

This comment has been minimized.

gabrieloliverio commented Mar 14, 2016

@yajra Incrementing manually the sequence and setting it to the table id worked, like you said Thanks a lot! It would be great if you put this information in your wiki ;)

Now I work with a proprietary framework and stored procedures, don't have a auto-increment trigger on my table.

This feature of auto-incrementing through custom sequences, when fully implemented, will work like the way I tried to do or it will be different? Also, your prefix_schema feature will be very welcome!

Thanks for your help!

@yajra

This comment has been minimized.

Owner

yajra commented Mar 15, 2016

This feature of auto-incrementing through custom sequences, when fully implemented, will work like the way I tried to do or it will be different

Yes, when this is fully implemented, you don't have to manually set the id value by getting the next sequence value manually.

@ChaosPower

This comment has been minimized.

Collaborator

ChaosPower commented Mar 15, 2016

@gabrieloliverio

Just issued PR #156 - L5.2.*

Please test when merged and tagged.

@ChaosPower ChaosPower assigned ChaosPower and yajra and unassigned ChaosPower Mar 15, 2016

@yajra

This comment has been minimized.

Owner

yajra commented Mar 18, 2016

@gabrieloliverio, I just released the PR of @ChaosPower which will basically complete the custom sequence feature of the package. See https://github.com/yajra/laravel-oci8/wiki/Oracle-Sequence#incrementing-model-using-custom-sequence-available-on-v522 for example usage.

Let us know if it works for you. Thanks!

@yajra

This comment has been minimized.

Owner

yajra commented Mar 18, 2016

BTW, this will only work on Eloquent models. If you will use query builder, you need to manually assign the next sequence value.

@gabrieloliverio

This comment has been minimized.

gabrieloliverio commented Mar 18, 2016

@yajra @ChaosPower Great job! Works like a charm now!

Thanks a lot for your efforts!

@yajra

This comment has been minimized.

Owner

yajra commented Mar 22, 2016

👍

@yajra yajra closed this Mar 22, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment