Laravel论坛-Chatter

时间:2019-06-04 16:32:57

标签: laravel exception forum

嗨,stackoverflow

我正在尝试为Laravel安装devdevdojo / chatter,但是在运行迁移时,它会失败并且无法真正找出原因。

在这里,您看到迁移失败。

public function up()
{
    Schema::table('chatter_discussion', function (Blueprint $table) {
        $table->foreign('chatter_category_id')->references('id')->on('chatter_categories')
                    ->onDelete('cascade')
                    ->onUpdate('cascade');
        $table->foreign('user_id')->references('id')->on('users')
                    ->onDelete('cascade')
                    ->onUpdate('cascade');
    });
    Schema::table('chatter_post', function (Blueprint $table) {
        $table->foreign('chatter_discussion_id')->references('id')->on('chatter_discussion')
                    ->onDelete('cascade')
                    ->onUpdate('cascade');
        $table->foreign('user_id')->references('id')->on('users')
                    ->onDelete('cascade')
                    ->onUpdate('cascade');
    });
}

public function down()
{
    Schema::table('chatter_discussion', function (Blueprint $table) {
        $table->dropForeign('chatter_discussion_chatter_category_id_foreign');
        $table->dropForeign('chatter_discussion_user_id_foreign');
    });
    Schema::table('chatter_post', function (Blueprint $table) {
        $table->dropForeign('chatter_post_chatter_discussion_id_foreign');
        $table->dropForeign('chatter_post_user_id_foreign');
    });
}

在这里您看到抛出异常:

    Migrating: 2016_07_29_171128_create_foreign_keys

   Illuminate\Database\QueryException  : SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table `chatter_discussion` add constraint `chatter_discussion_user_id_foreign` foreign key (`user_id`) references `users` (`id`) on delete cascade on update cascade)

  at /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
    660|         // If an exception occurs when attempting to run a query, we'll format the error
    661|         // message to include the bindings with SQL, which will make this exception a
    662|         // lot more helpful to the developer instead of just the database's errors.
    663|         catch (Exception $e) {
  > 664|             throw new QueryException(
    665|                 $query, $this->prepareBindings($bindings), $e
    666|             );
    667|         }
    668| 

  Exception trace:

  1   PDOException::("SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint")
      /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:458

  2   PDOStatement::execute()
      /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:458

  Please use the argument -v to see more details.

我真的希望你能明白我做错了什么。顺便说一下,这是从There githib找到的github标准文件的方式。

感谢您的时间:)

1 个答案:

答案 0 :(得分:0)

已修复。将用户表中的bigincrement编辑为增量

相关问题