Laravel:migrate:刷新不起作用

问题描述 投票:2回答:2

我从udemy.com学习Laravel,我遇到了migrate:refresh命令的问题。所以,当我尝试使用它时,我会看到信息

数组到字符串转换我尝试解决我的问题所以可能我犯了新的错误所以这是我的代码:Into UsersTableSeeder

    public function run()
{
    App\User::create([
        'name' => 'Kati',
        'email' => '[email protected]',
        'password' => bcrypt('password'),
        'admin' => 1
    ]);
    App\Profile::create([
        'user_id' => $user->id,
        'avatar' => 'link to avatar',
        'about' => 'Interested description',
        'youtube' => 'youtube.com',
        'facebook' => 'facebook.com'
    ]);
}

进入迁移

    public function up()
{
    Schema::create('profiles', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('user_id');
        $table->text('about');
        $table->string('youtube');
        $table->string('facebook');
        $table->timestamps();
    });
}

    public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('email')->unique();
        $table->string('password');
        $table->boolean('admin')->default(0);
        $table->rememberToken();
        $table->timestamps();
    });
}

我尝试从github克隆我的存储库并刷新但我遇到了一些问题。

php laravel migrate
2个回答
0
投票

这应该工作:

public function run()
{
    $user = App\User::create([
        'name' => 'Kati',
        'email' => '[email protected]',
        'password' => bcrypt('password'),
        'admin' => 1
    ]);

    App\Profile::create([
        'user_id' => $user->id,
        'about' => 'Interested description',
        'youtube' => 'youtube.com',
        'facebook' => 'facebook.com'
    ]);
}

在您的运行语句中,您在App\Profile创建过程中引用变量$user->id。但是,它尚未实例化。此外,您正在尝试在个人资料中添加头像,因此您应该将其添加到Profile表中,或者像我一样将其从播种器中删除。


0
投票

我在播种机中解决了这个问题:

'user_id' =>\App\User::pluck('id')->random();
© www.soinside.com 2019 - 2024. All rights reserved.