【发布时间】:2020-04-15 18:47:07
【问题描述】:
我有 2 个表,当我尝试迁移时返回给我这个错误:
一般错误:1005 Can't create table
usee_anbari.#sql-473_21177(errno: 150 "Foreign key constraint is wrongly form") (SQL: alter tablecompaniesadd constraintcompanies_access_id_foreignforeign key (@987654325) @) 在删除级联时引用accesses(id)
这是我的桌子:
public function up()
{
Schema::create('companies', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->text('address');
$table->string('tel1');
$table->string('tel2');
$table->integer('owner');
$table->unsignedBigInteger('access_id');
$table->string('depot_number')->default(2);
$table->timestamps();
$table->foreign('access_id')->references('id')->on('accesses')
->onDelete('cascade');
});
}
还有一个:
public function up()
{
Schema::create('accesses', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('type');
$table->string('description');
$table->timestamps();
});
}
我想念什么?
【问题讨论】:
-
这就是你的表的创建顺序吗?表
accesses需要存在才能引用它 -
@kerbholz 在我的本地主机中它已成功完成,但在服务器中只是返回此错误,当我想创建公司表时我收到错误
-
好吧,一个是 bigIncrements,另一个是 unsignedBigInteger,而你必须使用 bigInteger
-
@AlbertoSinigaglia
bigIncrements是unsignedBigInteger
标签: mysql database laravel mariadb laravel-6