I can't run the "php artisan migrate" in laravel project. If I run this command then below error will display.
Migrating: 2021_08_02_173519_create_access_user
Illuminate\Database\QueryException
SQLSTATE[42000]: Syntax error or access violation: 1072 Key column 'access_id' doesn't exist in table (SQL: alter table access_user add constraint access_user_access_id_foreign foreign key (access_id) references access (id))
at C:\Users\HETTIARACHCHIGEDAMIT\LanexGloble\lanex-internal-backend\api\vendor\laravel\framework\src\Illuminate\Database\Connection.php:692 688▕ // If an exception occurs when attempting to run a query, we'll format the error 689▕ // message to include the bindings with SQL, which will make this exception a 690▕ // lot more helpful to the developer instead of just the database's errors. 691▕ catch (Exception $e) { 693▕ $query, $this->prepareBindings($bindings), $e 694▕ ); 695▕ } 696▕ }
1 C:\Users\HETTIARACHCHIGEDAMIT\LanexGloble\lanex-internal-backend\api\vendor\laravel\framework\src\Illuminate\Database\Connection.php:485 \Database\Conne PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1072 Key column 'access_id' doesn't exist in table") in table")
2 C:\Users\HETTIARACHCHIGEDAMIT\LanexGloble\lanex-internal-backend\api\vendor\laravel\framework\src\Illuminate\Database\Conne\Database\Connection.php:485 PDOStatement::execute()
this is an error occurred file.
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateAccessUser extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('access_user', function (Blueprint $table) {
$table->increments('id');
$table->foreign('access_id')->references('id')->on('access');
$table->foreign('user_id')->references('id')->on('user');
$table->boolean('status');
$table->timestamp('updated_at');
$table->timestamp('created_at');
$table->string('updated_by');
$table->string('created_by');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('access_user');
}
}
$table->unsignedBigInteger('access_id');before you define the foreign keys. It looks like you will have to do the same foruser_idas well.