【发布时间】:2018-06-28 08:53:49
【问题描述】:
当我运行迁移以创建外键约束时,我在命令提示符中收到以下错误。我需要帮助来克服它,因为我在互联网上搜索了很多东西并尝试了各种各样的东西,但不幸的是没有一个有效
在 Connection.php 第 647 行:
SQLSTATE[42000]: 语法错误或访问冲突: 1064 You have an error i
n 你的 SQL 语法;检查与您的 MariaDB 服务器相对应的手册
在第 1 行 (
SQL: alter table category_posts add constraint category_posts_post_id_fo
reign foreign key (post_id) references posts () on delete cascade)
在 Connection.php 第 445 行:
SQLSTATE[42000]: 语法错误或访问冲突: 1064 You have an error i n 你的 SQL 语法;检查与您的 MariaDB 服务器相对应的手册 在第 1 行的“删除级联”附近使用正确语法的版本
我的外键约束迁移代码如下
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCategoryPostsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('category_posts', function (Blueprint $table) {
$table->integer('category_id')->unsigned()->index();
$table->integer('post_id')->unsigned()->index();
$table->foreign('post_id')->referances('id')->on('posts')->onDelete('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('category_posts');
}
}
请帮帮我。谢谢
【问题讨论】: