Reputation: 53
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');
}
}
Upvotes: 1
Views: 845
Reputation: 3764
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.
Upvotes: 3