Laravel播种未填写字段 [英] Laravel Seeding Does not Fill in Fields

查看:74
本文介绍了Laravel播种未填写字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据库种子文件:

I have a database seed file:

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 migration:refresh --seed时,它将种子数据库并在联系人表中创建相关记录,不同的是它不会用种子数组中的任何信息填充字段.我对其他表使用了完全相同的语法,并且它们工作正常,并且我还彻底检查了每个字段,以确保它们与数据库字段匹配,但是无论我做什么,都无法正确播种.

When I run php artisan migrate:refresh --seed it seeds the database and creates the relevant record in the contacts table, except that it does not fill the fields with any of the information in the seed array. I am using the exact same syntax for other tables and they work fine, and I've also checked each field thoroughly to make sure they match the database fields but no matter what I do it will not seed correctly.

有人有什么想法吗?

推荐答案

原来的问题与我模型中的关系有关.

Turns out the issue was to do with relationships in my models.

对于这个问题的未来访问者:请确保检查模型中定义hasOne/hasMany/etc关系的所有功能.仔细阅读口才的文档.

For future visitors to this question: make sure to check all the functions in your models that define hasOne/hasMany/etc relationships. Read though the Eloquent docs for more.

这篇关于Laravel播种未填写字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆