I am working on a Laravel project with PhpMyAdmin and I am quite new to Laravel, I have created tables with models, and already migrated them, now I need to add new columns but when I add the columns and then migrate it shows that noting there to be migrated
Also same thin for the relationships, I applied 1-1 between 2 tables and migrated, but the database is not updated, and from time to time I got an error of duplicating session table as well, how to solve this?
Students table
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('students', function (Blueprint $table) {
$table->id();
$table->string(column:"Name");
$table->string(column:"Semester");
$table->unsignedBigInteger('project_id')->nullable(false);
$table->foreign('project_id')->references('id')->on('projects');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('students');
}
};
Projects table
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('projects', function (Blueprint $table) {
$table->id();
$table->string("Title");
$table->date("Start Date");
$table->date("End Date");
$table->date("Type");
$table->integer("Duration");
//$table->unsignedBigInteger("lecturer_id");
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('projects');
}
};
Project model
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class project extends Model
{
use HasFactory;
public function getStudnet(){
return $this->belongsTo('App\project');
}
}
Student model
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class student extends Model
{
use HasFactory;
public function getProject(){
return $this->hasOne('App\project');
}
}