Этот вопрос закрыт для ответов, так как повторяет вопрос Как решить ошибку миграции Laravel?
@artem_atlas

Как исправить General error: 1215 Cannot add foreign key constraint?

При выполнении php artisan migrate получаю данную ошибку:
Illuminate\Database\QueryException  : SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table `post_everyday_conect_to_tags` add constraint `post_everyday_conect_to_tags_post_id_foreign` foreign key (`post_id`) references `post_e
very_days` (`id`))

  at C:\OSPanel\domains\vs.develop\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   Doctrine\DBAL\Driver\PDOException::("SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint")
      C:\OSPanel\domains\vs.develop\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOStatement.php:123

  2   PDOException::("SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint")
      C:\OSPanel\domains\vs.develop\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOStatement.php:121

таблица post_every_days :
Schema::create('post_every_days', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('title');
            $table->text('body');
            $table->timestamps();
        });

таблица post_every_day_tags
Schema::create('post_every_day_tags', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name');
            $table->timestamps();
        });

таблица post_everyday_conect_to_tags с ошибкой:
public function up()
    {
        Schema::create('post_everyday_conect_to_tags', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('post_id')->unsigned();
            $table->foreign('post_id')->references('id')->on('post_every_days'); 

            $table->integer('tag_id')->unsigned();
            $table->foreign('tag_id')->references('id')->on('post_every_day_tags'); 
        });
    }

laravel 5.8
  • Вопрос задан
  • 161 просмотр
Ваш ответ на вопрос

Вопрос закрыт для ответов и комментариев

Потому что уже есть похожий вопрос.
Похожие вопросы