Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php artisan tinker中的Laravel数据库插入错误_Php_Database_Laravel_Sqlite_Eloquent - Fatal编程技术网

Php artisan tinker中的Laravel数据库插入错误

Php artisan tinker中的Laravel数据库插入错误,php,database,laravel,sqlite,eloquent,Php,Database,Laravel,Sqlite,Eloquent,带有消息“SQLSTATE[HY000]:一般错误:1表配置文件没有名为title的列(SQL:插入到“配置文件”(“title”、“description”、“user_id”、“updated_at”、“created_at”)值(asd,123123,2200-07-31 10:19:032020-07-31 10:19:03))中。 这就是我在“$profile->save();”时遇到的错误 我正在通过以下链接学习Laravel: 这是2020_07_31_074115_create

带有消息“SQLSTATE[HY000]:一般错误:1表配置文件没有名为title的列(SQL:插入到“配置文件”(“title”、“description”、“user_id”、“updated_at”、“created_at”)值(asd,123123,2200-07-31 10:19:032020-07-31 10:19:03))中。

这就是我在“$profile->save();”时遇到的错误 我正在通过以下链接学习Laravel:

这是2020_07_31_074115_create_profiles_table.php

   {
       Schema::create('profiles', function (Blueprint $table) {
           $table->bigIncrements('id');
           $table->unsignedBigInteger('user_id');
           $table->string('title')->nullable();
           $table->text('description')->nullable();
           $table->string('url')->nullable();
           $table->timestamps();

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

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

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

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

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

   {
       Schema::create('profiles', function (Blueprint $table) {
           $table->bigIncrements('id');
           $table->unsignedBigInteger('user_id');
           $table->string('title')->nullable();
           $table->text('description')->nullable();
           $table->string('url')->nullable();
           $table->timestamps();

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

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

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

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

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

如果这是您的本地开发环境,您可以运行:

php-artisan-migrate:fresh

根据设计,migrate命令对文件中的更改不敏感。它使用文件名来了解已运行的迁移以及需要运行的迁移

如果您已经编辑了文件,第二次运行
php artisan migrate
将无效


要进行更改以更改生产数据库,您需要进行新的迁移并更改表,您不需要编辑旧的迁移文件。

添加标题列后是否迁移了数据库<代码>表格配置文件没有名为title的列
表示您迁移了表格,但没有名为title的列。我在项目路径中执行了“php artisan迁移”,但它显示“无需迁移”。或者,在我更改代码(如npm run dev)后,是否需要执行此操作,或者重新打开cmd?我的答案解决了你的问题吗?@KurtFriars是的,先生,你的答案有效。多谢各位