php - 一般错误 : 1 near ")": syntax error") in Laravel 5. 6.33

标签 php mysql laravel sqlite

我在 Laravel Migrations 方面遇到一些问题。 我的文章和标签之间存在多对多关系。 “article_tag”迁移:

Schema::create('article_tag', function (Blueprint $table) {
    $table->integer('article_id')->unsigned()->index();
    $table->foreign('article_id')->refrences('id')->on('tags')->onDelete('cascade')->onUpdate('cascade');
    $table->integer('tag_id')->unsigned()->index();
    $table->foreign('tag_id')->refrences('id')->on('articles')->onDelete('cascade')->onUpdate('cascade');
});

“标签”迁移:

Schema::create('tags', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->timestamps();
});

'文章迁移:

Schema::create('articles', function (Blueprint $table) {
    $table->increments('id');
    $table->string('title');
    $table->text('body');
    $table->timestamps();
});

我的控制台日志:

Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 1 near ")": syntax error (SQL: create table "article_tag" ("article_id" integer not null, "tag_id" integer not null, foreign key("article_id") references "tags"() on delete cascade on update cascade, foreign key("tag_id") references "articles"() on delete cascade on update cascade)

异常跟踪:

1 PDOException::("SQLSTATE[HY000]: General error: 1 near ")": syntax error") /home/user/Desktop/blog/vendor/laravel/framework/src/Illuminate/Database/Connection.php:452

2 PDO::prepare("create table "article_tag" ("article_id" integer not null, "tag_id" integer not null, foreign key("article_id") references "tags"() on delete cascade on update cascade, foreign key("tag_id") references "articles"() on delete cascade on update cascade)") /home/user/Desktop/blog/vendor/laravel/framework/src/Illuminate/Database/Connection.php:452

最好,Javad

最佳答案

您的迁移中存在拼写错误。你说的是 references->() 但它应该是 references->()

Schema::create('article_tag', function (Blueprint $table) {
        $table->integer('article_id')->unsigned()->index();
// in here
        $table->foreign('article_id')->refrences('id')->on('tags')->onDelete('cascade')->onUpdate('cascade');
        $table->integer('tag_id')->unsigned()->index();
// and in here too
        $table->foreign('tag_id')->refrences('id')->on('articles')->onDelete('cascade')->onUpdate('cascade');
    });

关于php - 一般错误 : 1 near ")": syntax error") in Laravel 5. 6.33,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52056975/

相关文章:

javascript - 单击“应用”按钮并插入到另一个表中时从面板获取名称

php - 解析编码 $_SERVER ['request_uri' ]

php - Mailchimp API v3.0 添加待处理成员无需确认电子邮件

MySQL:慢日志;附加 CPU 使用率

php - Laravel 5.5 $exception instanceof AuthenticationException 未按预期工作

php - 如何从数据库中检索数据并能够在summernote编辑器中进行编辑?

php - 路由资源未定义 laravel 5.3

PHP/MySQL : How to delete all data from database which contains specific id in one query

mysql - sequelize 多个外键只包含一列

MySql 在使用带有模式的函数 WEEK() 时返回错误