1
votes

I've been trying to use migrations for a cross-dbms database. Using entrust and confide packages, I added migrations after them to add a user_statuses table and a reference in users table to user-statuses' ids; but as I define the foreign key I get this:

[Illuminate\Database\QueryException]
Error Code    : 2275
Error Message : ORA-02275: such a referential constraint already exists in the table
Position      : 53
Statement     : alter table users add constraint users_state_foreign foreign key ( state ) references user_statuses ( id ) (SQL: alter table users add constraint users_state_foreign foreign key ( state ) references user_statuses ( id ))

[yajra\Pdo\Oci8\Exceptions\SqlException]
Error Code    : 2275
Error Message : ORA-02275: such a referential constraint already exists in the table
Position      : 53
Statement     : alter table users add constraint users_state_foreign foreign key ( state ) peferences user_statuses ( id )

Below are the user_statuses and the alteration migration. user_status creation:

Schema::create('user_statuses', function($table){
    // Columns
    $table->increments('id')->unsigned();
    $table->string('name');

    // Indexes

    // Constraints
});

users alteration:

Schema::table('users',function($table){
    // Columns
    $table->integer('state')->unsigned();
    $table->softDeletes();

    // Indexed

    // Constraints
    $table->foreign('state')->references('id')->on('user_statuses');
});
2
The database you're using already has a constraint named USERS_STATE_FOREIGN. Try executing the following: SELECT * FROM ALL_CONSTRAINTS WHERE CONSTRAINT_NAME = 'USERS_STATE_FOREIGN'. Best of luck.Bob Jarvis - Reinstate Monica
Thanks @BobJarvis ! I run the migrations for a fresh DB (I even purge the remaining). I have tried changing the constraint's name, column name. I removed the foreign key definition that I am aware of and there will be no constraints. I have tested the migrations with mysql and they seem to be ok. I run pure queries and they are ok. I am going to risk to think this might have to do something with the yajra/laravel-oci8 package or migration itself, that calls that line more than once!Cunning
Personally, I won't use any variety of database "framework" because my observation is that they cause more issues than they solve. YMMV.Bob Jarvis - Reinstate Monica
@BobJarvis I'm with you on this. This was an enforced corporation's decision.Cunning

2 Answers

1
votes

This is already fix at version https://github.com/yajra/laravel-oci8/tree/v1.5.11

Please try or submit an issue to our repo.

0
votes

I put the foreign() statement in another, new Schema::table() statement in the same file, just bellow the one that creates columns as bellow:

Schema::table('users', function($table){
    // Columns
    $table->integer('kojak')->unsigned();
    $table->softDeletes();

    // Indexed

    // Constraints

});
Schema::table('users', function($table){
    $table->foreign('kojak')->references('id')->on('user_statuses');
});

This solved my problem, but the question remains why the conventional code doesn't work.