如何解决Laravel 8 de 迁移过程中的外部错误
我们想将 RequestTypeID
表中的 Request
作为外键分配给 RequestTypeID
表中的 DefRequestType
列,但出现以下错误。
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table `Request` add constraint `request_requesttypeid_foreign` foreign key (`RequestTypeID`) references `DefRequestType` (`RequestTypeID`))
我们通过将表引擎修复为 MyISAM
来解决问题,但我们希望将表引擎用作 InnoDB
。此外,我们正在 Laravel 8 版本中尝试迁移过程。首先创建 DefRequestType 表,然后创建请求表。我后来在 DefRequestType 表中将 DefRequestTypeID 列的值更改为 bigIncrements 的原因是在 DefRequestType 表中分配两个主键。我还希望能够为 DefRequestTypeID 列提供一个额外的 autoIncrement 属性。
请求表
Schema::create('Request',function (Blueprint $table) {
$table->bigIncrements('RequestID');
$table->unsignedBigInteger('RequestTypeID')->nullable(); <----------------------------
$table->unsignedInteger('CustomerID')->nullable();
$table->unsignedInteger('ApplicationID')->nullable();
$table->foreign('RequestTypeID')
->references('RequestTypeID')
->on('DefRequestType');
$table->foreign('ContentID')
->references('ContentID')
->on('Content');
});
DefRequestType 表
Schema::create('DefRequestType',function (Blueprint $table) {
$table->unsignedInteger('DefRequestTypeID');
$table->unsignedBigInteger('RequestTypeID'); <----------------------------
$table->string('RequestDefinition');
$table->integer('Status')->default(1);
$table->integer('OldID');
$table->primary(['DefRequestTypeID','RequestTypeID']);
});
Schema::table('DefRequestType',function (Blueprint $table) {
$table->bigIncrements('DefRequestTypeID')->change();
});
如果您能提供帮助,我们将不胜感激。
解决方法
问题出在表 q)raze(`a`a`b!1 2 3;`a`b!9 9)
a| 9
b| 9
q)
q)(`a`a`b!1 2 3),`a`b!9 9
a| 9
a| 2
b| 9
q)
q)({x,y}/)(`a`a`b!1 2 3;`a`b!9 9)
a| 9
a| 2
b| 9
上,列 DefRequestType
是一个普通整数。在外键上,DefRequestTypeID
是一个大整数。
要解决此问题,请将 RequestTypeID
更改为普通整数或将 RequestTypeID
更改为大整数。
编辑
我会将其更改为以下内容。
DefRequestTypeID
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。