1
votes

The error

Illuminate/Database/QueryException with message 'SQLSTATE[HY000]: General error: 1 table profiles has no column named title (SQL: insert into "profiles" ("title", "description", "user_id", "updated_at", "created_at") values (asd, 123123, 2, 2020-07-31 10:19:03, 2020-07-31 10:19:03))'

This the error I faced when '$profile -> save();' I am learning Laravel according to the below link: https://www.youtube.com/watch?v=ImtZ5yENzgE&list=WL&index=45&t=81s

This is the 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');
   }

This is the 2014_10_12_000000_create_users_table.php

<?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');
    }
}
1
Have you migrated your database since adding the title column? table profiles has no column named title means you have the table migrated, but there is not a column named title. - Kurt Friars
I have do "php artisan migrate" at my project path but it shows "Nothing to migrate." Or is that anything to do while after I change the code like npm run dev, or reopen the cmd? - Wei Hong
Did my answer solve your issue? - Kurt Friars
@KurtFriars Yes sir, ur answer is working. Thank you so much - Wei Hong

1 Answers

2
votes

If this is your local development environment, you can run:

php artisan migrate:fresh

The migrate command is not sensitive to changes in the files, by design. It uses the file names to know what migrations it has already run, and which ones need to be run.

Running php artisan migrate a second time will have no effect if you have edited the files.

To make changes that will alter your production db, you make new migrations and alter the tables, you do not edit your old migration files.