1

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 is the error I faced when using '$profile -> save();'

This is the 2020_07_31_074115_create_profiles_table.php:

public function up()
{
    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');
    }
}
2
  • 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. Commented Jul 31, 2020 at 10:35
  • 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? Commented Jul 31, 2020 at 10:56

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.