我有一个数据库种子文件:
class ContactTableSeeder extends Seeder {
    public function run()
    {
        $contacts = array(
            array(
                'first_name'        => 'Test',
                'last_name'         => 'Contact',
                'email'             => 'test.contact@emai.com',
                'telephone_number'  => '0111345685',
                'address'           => 'Address',
                'city'              => 'City',
                'postcode'          => 'postcode',
                'position'          => 'Director',
                'account_id'        => 1
           )
        );
        foreach ($contacts as $contact) {
            Contact::create($contact);
        }
    }
}当我运行php artisan migrate:refresh --seed时,它会对数据库进行种子设定,并在contacts表中创建相关记录,但它不会用seed数组中的任何信息填充字段。我对其他表使用了完全相同的语法,它们工作得很好,我还彻底检查了每个字段,以确保它们与数据库字段匹配,但无论我做什么,都不会正确地设定种子。
有谁有什么想法吗?
发布于 2015-11-15 13:32:27
我也遇到了同样的问题,但上面的解决方案对我来说都不起作用。事实证明这是因为我的模型中有一个构造函数!在我移除它之后,它工作得很好!
public function __construct()
{
    parent::__construct();
}编辑:在进一步阅读后,我发现问题是由于以下事实造成的:如果要在模型中包含构造函数,则必须接受属性参数并将其传递给父函数。如果你这样做了,那么构造函数就不会破坏DB种子(可能还有其他东西)。我希望这不会让别人头疼。
public function __construct($attributes = array())
{
    parent::__construct($attributes);
}https://stackoverflow.com/questions/16497481
复制相似问题