【问题标题】:Illuminate \ Database \ QueryException (42P01) SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "suggesteds" does not exist LINE 1Illuminate \ Database \ QueryException (42P01) SQLSTATE[42P01]: Undefined table: 7 ERROR: relationship "suggesteds" does not exist LINE 1
【发布时间】:2021-09-21 19:47:23
【问题描述】:

我试图使用此处的代码在 laravel 中创建迁移。但不幸的是,它会弹出一个像这里给出的错误。

我使用 PostgreSQL 9.2.24

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateSuggestedsTable extends Migration
{
/**
 * Run the migrations.
 *
 * @return void
 */
 public function up()
 {
    Schema::create('suggesteds', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('channel_id')->unsigned()->index();
        $table->string('group')->nullable()->index(); // 'technology', 
    'lifestyle', etc.
        $table->string('language')->default('en')->index();
        $table->integer('z_index')->default(0);
        $table->timestamps();
    });
    }

  /**
   * Reverse the migrations.
   *
   * @return void
   */
   public function down()
   {
    Schema::dropIfExists('suggesteds');
   }
   }

在我使用 MySQL 之前并没有它的错误。 任何帮助将不胜感激。

【问题讨论】:

标签: laravel postgresql


【解决方案1】:

请使用:

php artisan migrate:refresh

【讨论】:

    【解决方案2】:

    从数据库中手动删除suggesteds 表(如果存在),然后再次运行迁移脚本。

    你也应该检查这个issue

    【讨论】:

      【解决方案3】:

      你可以试试:

      <?php
      
      use Illuminate\Database\Migrations\Migration;
      use Illuminate\Database\Schema\Blueprint;
      use Illuminate\Support\Facades\Schema;
      
      class CreateSuggestedsTable extends Migration
      {
          /**
           * Run the migrations.
           *
           * @return void
           */
          public function up()
          {
              Schema::create('suggesteds', function (Blueprint $table) {
                  $table->increments('id');
                  $table->integer('channel_id')->unsigned()->index();
                  $table->string('group')->nullable()->index();
                  $table->string('language')->default('en')->index();
                  $table->integer('z_index')->default(0);
                  $table->timestamps();
              });
          }
      
          /**
           * Reverse the migrations.
           *
           * @return void
           */
          public function down()
          {
              Schema::dropIfExists('suggesteds');
          }
      }
      

      【讨论】:

      • 您好,感谢您的回答,但这似乎是一个相当大的代码块,没有任何解释!请考虑添加有关此代码作用的说明。
      猜你喜欢
      • 1970-01-01
      • 2021-12-20
      • 2021-01-29
      • 1970-01-01
      • 2020-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-09
      相关资源
      最近更新 更多