找不到基本表或视图找不到表'tenancy.websites'

时间:2018-10-31 15:06:12

标签: php laravel laravel-5.7

安装hyn多租户程序包并运行php artisan tenancy:migrate后,出现错误“找不到基本表”。该命令应该迁移三个迁移。第一个是2017_01_01_000003_tenancy_websites.php。这是内容...

<?php

class TenancyWebsites extends AbstractMigration
{
    protected $system = true;

    public function up()
    {
        Schema::create('websites', function (Blueprint $table) {
            $table->bigIncrements('id');

            $table->string('uuid');

            $table->timestamps();
            $table->softDeletes();
        });
    }

    public function down()
    {
        Schema::dropIfExists('websites');
    }
}

然后2017_01_01_000005_tenancy_hostnames.php。这是内容...

<?php

class TenancyHostnames extends AbstractMigration
{
    protected $system = true;

    public function up()
    {
        Schema::create('hostnames', function (Blueprint $table) {
            $table->bigIncrements('id');

            $table->string('fqdn')->unique();
            $table->string('redirect_to')->nullable();
            $table->boolean('force_https')->default(false);
            $table->timestamp('under_maintenance_since')->nullable();
            $table->bigInteger('website_id')->unsigned()->nullable();

            $table->timestamps();
            $table->softDeletes();

            $table->foreign('website_id')->references('id')->on('websites')->onDelete('set null');
        });
    }

    public function down()
    {
        Schema::dropIfExists('hostnames');
    }
}

然后2017_01_01_000003_tenancy_hostnames.php。这是内容...

class TenancyWebsitesNeedsDbHost extends AbstractMigration
{
    protected $system = true;

    public function up()
    {
        Schema::table('websites', function (Blueprint $table) {
            $table->string('managed_by_database_connection')
                ->nullable()
                ->comment('References the database connection key in your database.php');
        });
    }

    public function down()
    {
        Schema::table('websites', function (Blueprint $table) {
            $table->dropColumn('managed_by_database_connection');
        });
    }
}

我遵循了他们文档中的所有步骤。代码有什么问题?

1 个答案:

答案 0 :(得分:1)

代码中...的文件名都没有正确排序。 执行顺序基于文件名 这是你的订单

  1. 2017_01_01_000003_tenancy_hostnames.php
  2. 2017_01_01_000003_tenancy_websites.php
  3. 2017_01_01_000005_tenancy_hostnames.php

正确的顺序应该是(用包含的相同的类名命名)

  1. 2017_01_01_000003_TenancyWebsites.php
  2. 2017_01_01_000005_TenancyHostnames.php
  3. 2017_01_01_000007_TenancyWebsitesNeedsDbHost.php
相关问题