本文介绍了通过sqlite插入数据时Laravel中的PHP错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究Laravel并从事php artisan的研究,但我不断遇到此错误:

I'm studying Laravel and working around in php artisan but I keep on getting this error:

我将个人资料附加到用户,并且我的用户表中包含内容:

I am attaching a Profile to a User and my User table has contents:

>> User::all()
=> Illuminate\Database\Eloquent\Collection {#2992
     all: [
       App\User {#2993
         id: "1",
         name: "Test User1",
         email: "test1@test.com",
         username: "test1",
         email_verified_at: null,
         created_at: "2020-03-12 02:01:08",
         updated_at: "2020-03-12 02:01:08",
       },
     ],    }

这是我在PHP Artisan中输入的内容

This is what I entered in PHP Artisan

>>> $profile = new \App\Profile();
=> App\Profile {#2987}
>>> $profile->title = 'Cool Title';
=> "Cool Title"
>>> $profile->description = 'Desc';
=> "Desc"
>>> $profile->user_id = 1;
=> 1
>>> $profile->save();

Profiles_table.php

Profiles_table.php

class CreateProfilesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('profiles', function (Blueprint $table) {
            $table->bigIncrements('id')->nullable;
            $table->unsignedBigInteger('user_id')->nullable;
            $table->string('title')->nullable;
            $table->text('description')->nullable;
            $table->string('url')->nullable;
            $table->timestamps();

            $table->index('user_id');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('profiles');
    }

}

Create_users_table.php

Create_users_table.php

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name')->nullable();
            $table->string('email')->unique();
            $table->string('username')->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password')->nullable();
            $table->rememberToken()->nullable();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}

我找不到它失败的原因.希望有人能找出原因.谢谢

I can't find the reason why it is failing. Hope someone can find out what is causing it. Thanks

推荐答案

我认为您的个人资料"迁移中有错字.

I think there is a typo on your 'profile' migration.

$table->string('url')->nullable;

$table->string('url')->nullable();

这篇关于通过sqlite插入数据时Laravel中的PHP错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 09:51
查看更多