我一直在尝试使用跨dbms数据库的迁移。使用委托和信任包,我在它们之后添加了迁移,以添加user_statuses表和users表中对用户状态id的引用;但当我定义外键时,我得到了这个:
[照明''数据库''查询异常]错误代码:2275错误消息:ORA-02275:表中已经存在这样的引用约束职位:53语句:alter table users add constraint users_state_foreign外键(state)references user_statuses(id)(SQL:alter table users addconstraint用户_state_foreign主键(state)references user_statuces(id))[yajra''Pdo''Oci8''Exceptions''SqlException]错误代码:2275错误消息:ORA-02275:表中已经存在这样的引用约束职位:53语句:更改表用户添加约束users_state_foreign外键(state)引用user_statuses(id)
以下是user_statuses和变更迁移。user_status创建:
Schema::create('user_statuses', function($table){
// Columns
$table->increments('id')->unsigned();
$table->string('name');
// Indexes
// Constraints
});
用户更改:
Schema::table('users',function($table){
// Columns
$table->integer('state')->unsigned();
$table->softDeletes();
// Indexed
// Constraints
$table->foreign('state')->references('id')->on('user_statuses');
});
这已经在版本中修复https://github.com/yajra/laravel-oci8/tree/v1.5.11
请尝试或将问题提交给我们的回购。
我把foreign()
语句放在同一文件中的另一个新的Schema::table()
语句中,就在创建列的语句下面,如下所示:
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');
});
这解决了我的问题,但问题仍然是为什么传统代码不起作用。