Laravel / SQL |外键约束格式错误

时间:2019-04-18 08:31:13

标签: php mysql sql laravel mariadb

我在为表迁移时设置外键时遇到问题。 这是代码:

public function up()
{
    Schema::table('ticket', function (Blueprint $table) {
        $table->integer('respondent_id')->nullable();
        $table
            ->foreign('respondent_id', 'ticket_respondent_id_foreign')
            ->references('users')->on('id')->onDelete('set null');
    });
}

public function down()
{
    Schema::table('ticket', function (Blueprint $table) {
        $table->dropForeign('ticket_respondent_id_foreign');
        $table->dropColumn('respondent_id');
    });
}

错误:

  

Illuminate \ Database \ QueryException:SQLSTATE [HY000]:常规错误:   1005无法创建表lamourka#sql-1_628(错误号:150“ Foreign   键约束的格式不正确”)(SQL:alter table ticket add   约束ticket_respondent_id_foreign外键   (respondent_id)在删除集上引用了idusers

     在

  /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664

     

异常跟踪:

     

1 Doctrine \ DBAL \ Driver \ PDOException::(“” SQLSTATE [HY000]:常规   错误:1005无法创建表lamourka#sql-1_628(错误号:150   “外键约束的格式不正确”)“)         /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:119

     

2 PDOException::(“” SQLSTATE [HY000]:常规错误:1005无法   创建表lamourka#sql-1_628(错误号:150“外键   约束的格式不正确“)”)         /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:117

Here's users' column. (Yeah, yeah, it's signed :| )

0 个答案:

没有答案