laravel 5.1播种时未定义的表

时间:2015-07-09 07:54:24

标签: php laravel laravel-5.1

我有模型广告系列

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use App\CampaignsTargetGeo;
use App\CampaignsTargetCategory;

class Campaigns extends Model
{

const DEFAULT_MARGINALITY = 1.2;

protected $table = 'campaigns';
public $fillable = [
    'name',
    'url',
    'user_rate_min',
    'user_rate_max',
    'network_rate_min',
    'network_rate_max',
    'daily_limit',
    'hourly_limit',
    'status_id',
    'user_id'
];

并播种CampaignsSeeder

<?php

use Illuminate\Database\Seeder;
use App\Campaigns;

class CampaignsSeeder extends Seeder
{
/**
 * Run the database seeds.
 *
 * @return void
 */
public function run() {
    $campaigns = \DB::table('campaigns')->insert([
        'id'               => 1,
        'name'             => 'test campaign',
        'url'              => 'http://example.com?test=true',
        'user_rate_min'    => '80',
        'user_rate_max'    => '100',
        'network_rate_min' => '100',
        'network_rate_max' => '120',
        'daily_limit'      => '10000',
        'hourly_limit'     => '1000',
        'status_id'        => '1',
        'user_id'          => '1'
    ]);
}
}

和数据库播种器类

<?php

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

class DatabaseSeeder extends Seeder
{
/**
 * Run the database seeds.
 *
 * @return void
 */
public function run()
{
    Model::unguard();

     $this->call('UserSeeder');
     $this->call('DictionariesTargetGeoSeeder');
     $this->call('DictionariesTargetCategoriesSeeder');
     $this->call('DictionariesCampaignStatusesSeeder');
     $this->call('CampaignsSeeder');

    Model::reguard();
}

}

当我运行php artisan db:seed时,我有这个错误

➜  panel git:(master) ✗ pa db:seed
Seeded: UserSeeder
Seeded: DictionariesTargetGeoSeeder
Seeded: DictionariesTargetCategoriesSeeder
Seeded: DictionariesCampaignStatusesSeeder

[Illuminate\Database\QueryException]
SQLSTATE[42P01]: Undefined table: 7 ERROR:  relation "campaigns" does not exist  LINE 1: insert into "campaigns" ("id", "name", "url", "user_rate_min...                      ^ (SQL: insert into "campaigns" ("id", "name", "url", "user_rate_min", "user_rate_max", "network_rate_min", "network_rate_max", "daily_limit", "hourly_limit", "status_id", "user_id") values (1, test campaign, http://example.com80test=true, 100, 100, 120, 10000, 1000, 1, 1, ?))

[PDOException]
SQLSTATE[42P01]: Undefined table: 7 ERROR:  relation "campaigns" does not   exist LINE 1: insert into "campaigns" ("id", "name", "url", "user_rate_min...
                  ^

但桌子存在!我检查psql控制台。这个时刻可能没有提交交易吗?

如果我运行➜ panel git:(master) ✗ php artisan db:seed --class=CampaignsSeeder它可以正常运行

为什么呢? : - )

1 个答案:

答案 0 :(得分:0)

idman /d URL [/p local_path] [/f local_file_name] [/q] [/h][/n] [/a]方法需要一个数组数组(每行一个数组),但是您要插入一个数组。试试

insert()