【问题标题】:Some Laravel seeders not doing anything - no errors, but no data inserted into table一些 Laravel 播种机没有做任何事情 - 没有错误,但没有数据插入到表中
【发布时间】:2017-08-28 18:08:28
【问题描述】:

所以我的应用程序中有五个种子 - 其中四个种子没有问题,第五个没有向数据库插入数据,但不返回任何错误。格式与其他播种机相同,所以我不确定这可能是什么。代码如下:

DatabaseSeeder.php

<?php

use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;

class DatabaseSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $this->call(RoleSeeder::class);
        $this->call(UserSeeder::class);
        $this->call(DomainSeeder::class);
        $this->call(SiteSeeder::class);
        $this->call(SyncSeeder::class);
    }
}

SyncSeeder.php(工作示例)

<?php

use Illuminate\Database\Seeder;
use App\Sync;

class SyncSeeder extends Seeder{

    public function run(){
        DB::table('sites')->delete();

        Sync::create(array(
            'synced_at'       => 0,
        ));
    }
}

SiteSeeder.php(不工作)

<?php

use Illuminate\Database\Seeder;
use App\Site;

class SiteSeeder extends Seeder{

    public function run(){
        DB::table('sites')->delete();

        Site::create(array(
            'site_name'     => '...',
            'description'   => '...,
            'connection_id' => '...',
            'host'          => '...',
            'port'          => '...',
            'database_name' => '...',
            'username'      => '...',
            'password'      => '...'
        ));

        Site::create(array(
            'site_name'     => '...',
            'description'   => '...',
            'connection_id' => '...',
            'host'          => '...',
            'port'          => '...',
            'database_name' => '...',
            'username'      => '...',
            'password'      => '...'
        ));

    }
}

非常感谢任何有关调试的提示!

【问题讨论】:

  • 您正在删除 SyncSeeder 中的所有网站...
  • 男孩,我觉得自己很愚蠢吗...非常感谢

标签: php mysql laravel seeding


【解决方案1】:

您可以尝试不使用这部分代码吗?

DB::table('sites')->delete();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-22
    • 2019-03-16
    • 2011-02-10
    • 1970-01-01
    • 2021-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多